Sublime Forum

PHP regex breaks syntax highlight

#1

Looks like that some combinations of characters in a regex expression may break the syntax highlight. At least for PHP. I’ve noticed this since few versions of sublime, so it’s not something new.

Here is a screenshot:

0 Likes

#2

can you share your example as a formatted code block please? so we can copy and paste it into ST?. So far, I haven’t been able to replicate on build 3125. What build are you using?

0 Likes

#3

This is the code:
$preg1 = preg_replace('/([\(\)\$\-\.\/\\\])/', '\\\$1', $term);

I am on build 3125 too.

0 Likes

#4

looks like you are escaping the ], which is causing it to not recognize/expect the closing quote/apostrophe. If you change it to: $preg1 = preg_replace('/([\(\)\$\-\.\/\\\\])/', '\\\$1', $term); then it will work.

Also you don’t need to escape all those characters in a character class, the following should also work just as well:

$preg1 = preg_replace('/([()$\-.\/\\])/', '\\\$1', $term);

not sure, but maybe you don’t even need to escape the /.

0 Likes

#5

Yes, true, looks like there is a lot of escaping in that code. But indeed, if I stop escaping the ] it works.

Thanks.

0 Likes