Home Download Buy Blog Forum Support

Regex Help

Regex Help

Postby C0D312 on Thu Dec 01, 2011 8:47 pm

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?
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am

Re: Regex Help

Postby facelessuser on Thu Dec 01, 2011 9:08 pm

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.
Code: Select all
([\w]+)(?=(?![\n\r]+)\s*somestring)


regex.jpg
regex.jpg (7.46 KiB) Viewed 940 times


There are probably a number of different ways to do this.
facelessuser
 
Posts: 1567
Joined: Tue Apr 05, 2011 7:38 pm

Re: Regex Help

Postby C0D312 on Sat Dec 03, 2011 7:35 pm

Finally managed to get my plugin working. Thanks again for your help.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests