Regex match before pattern, stepping back until '}'

Sayth

Gawd
Joined
Oct 7, 2001
Messages
618
Hey super smart Hardforum peeps!

Anyone happen to be good with Regex? I'm using C#, and am looking for an expression that will find a set pattern. then match all characters all the way backwards until it meets the first }

So I have this, but it's obviously just grabbing 5 characters back.

Code:
.{5}(?=({[a-fA-F0-9-]{36}}))

Code:
https://www.bing.com/search?q={searchTerms}&FORM=referrer:source}0GoogleN{445487C1-C52F-454C-B3BF-1228339320DD} https://www.google.ca/search?q={searchTerms}&ie={inputEncoding?}&oe={outputEncoding?}YahooN{62854BBE-65F1-4D5D-8498-6D75744069CA}https://ca.search.yahoo.com/search?p={searchTerms}

So my goal is to match 0GoogleN and Yahoo so I can insert a newline before and after it. The desired value can change frequently.

Thanks all!
-Sayth
 
Looks like I got it!

(?<=})([0-9a-zA-Z])*(?=({[a-fA-F0-9-]{36}}))

Now using it in my C# I've tried
Code:
textEditor.Text = Regex.Replace(textEditor.Text, "(?<=})([0-9a-zA-Z])*(?=({[a-fA-F0-9-]{36}}))", "\n\n$1");

But the problem is that it works perfect for the first hit, but then each hit after that the matched text is deleted.
 
There we go...

Code:
textEditor.Text = Regex.Replace(textEditor.Text, "(?<=})([0-9a-zA-Z])*(?=({[a-fA-F0-9-]{36}}))", "\n\n$0\n");

Well I hope this helps someone else! I spent too many hours on this yesterday!

Peace!
 
Back
Top