• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

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