1

I have an input string:

str= "row1:=dep_id=1,salary<3000;row22:=dep_id=1,salary<3000; row33:=dep_id=5,salary>5000"

Regex pattern:

regex.Pattern = "row\d+:=(.*?);"

Output:

MatchCollectionItem: row1:=dep_id=1,salary<3000;
SubMatchItem: dep_id=1,salary<3000

MatchCollectionItem: row22:=dep_id=1,salary<3000;
SubMatchItem: dep_id=1,salary<3000

It does not return the last ("row33...") because it ends without ";".

I've tried a few variations for the pattern

regex.Pattern = "row\d+:=(.*?)[;$]"
regex.Pattern = "row\d+:=(.*?)[;|$]"

However, the result is the same.

How to "tell" the the regex to match everything ending with ";" OR the end of string?

I need regex solution only, please.

1
  • 1
    $ inside of a character set gets treated as a literal dollar sign, not an end line anchor. You want (?:;|$) Commented Jul 26, 2021 at 14:06

1 Answer 1

2

Try this pattern with multiline option enabled:

row\d+:=(.*?)(?:;|$)

Using square brackets, the $ gets treated as a Dollar sign.

For trying out RegEx-patterns, I use regexr.com.

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.