2

I am new to regex and it really confuses me. What I am trying to accomplish is finding the string between 2 specified characters where the string should contain another specified character within it.

String Example: 'Help--Me'

In this case I would be looking for the string Help Me that's between the two apostrophes and contains -- in it.

The Regex I have currently is @"(?<=\')(--.*?)(?=\')" This seems to only work if the -- is at the beginning of the string Example: '--HelpMe'

Thanks in advance

1 Answer 1

4

You're very close—nice attempt. You need another wildcard string at the beginning:

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

This way, it'll look for a string of any characters following the ' (the minimum string, by the way, due to the non-greedy quantifier, *?), a --, another string of any characters (again, the minimum string), and finally the closing '.

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

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.