1

so I'm having issues with finding regex match in textbox2.text (the text looks like a javascript file) here is my code:

string file = Regex.Match(textBox2.Text, @"rl='(.*)'", RegexOptions.IgnoreCase).Groups[0].Value;

I'm trying to find what is between rl=' & ' but I'm getting what is between + rl=' and ' the "()" don't seem to work? >.<

Any idea what is the issue?

1
  • Try non-greedy quantifier: (.*?) instead of (.*) Commented Oct 20, 2012 at 14:31

2 Answers 2

2

try this regex pattern,

(?<=rl=').*(?=')

See Lookahead and Lookbehind Zero-Width Assertions.

sample demo

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

.* doesnt work here..should use .*? else would match greedily
@Anirudha it depends on what you want, if you have text, rl='the address is st paul's village' will result the address is st paul. using .*? will make it lazy.
2

I'm trying to find what is between rl=' & '

You should use this regex then

@"(?<=rl\=').*?(?=')"

This regex tells the engine to match 0-n number of characters i.e(.*?) which has rl=' at the beginning of it i.e(?<=rl\=') and end's with a ' i.e(?=')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.