How do I make Regex stop the search after “Target This”?
HeaderText="Target This" AnotherAttribute="Getting Picked Up"
This is what i’ve tried
var match = Regex.Match(string1, @"(?<=HeaderText=\").*(?=\")");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The quantifier
*is eager, which means it will consume as many characters as it can while still getting a match. You want the lazy quantifier,*?.As an aside, rather than using look-around expressions as you have done here, you may find it in general easier to use capturing groups:
Now the
matchmatches the whole thing, butmatch.Groups[1]is just the value in the quotes.