Sublime Forum

Regex Help

#1

Unfortunately, I never really took the time to learn regex. So, I need some help for my plugin.

I have a string that I know exists in a file. I need a regular expression that returns the word preceding my string. Anyone have a suggestion?

0 Likes

#2

I am far from an expert in regex, but I have found the more you read about it and try to use it, the better you get.

I don’t know if this is perfect, but it is trying to find a word that is followed by a string, but that word is also not followed by an new line to make sure the string is on the same line as the preceding word.

(\w]+)(?=(?!\n\r]+)\s*somestring)


There are probably a number of different ways to do this.

0 Likes

#3

Finally managed to get my plugin working. Thanks again for your help.

0 Likes