Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to identify a repetitive type of patter with regex (c#)

Currently I’m doing:

Regex.Match(ln, "\"[\\u0000-\\u007E]+\"")

The problem is if ln is like ""text…"" it won’t work as wanted.

Same to """text…""", etc…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can i make the " " repetitive?

It should also match to "text1"text2"text3".

The point is, it should match with the most 2 outer " " if the number of " is par or cut the last " if number impar.

Ex: "stack"overflow" -> match "stack"

Ex: "stack""overflow" -> match "stack""overflow"

Ex: text1""text2""text3 -> match ""text2""

Ex: "text1"text2"text3 -> match "text1"

Any idea how to make this pattern?

>Solution :

An idea is to work with negated " between.

  • Match "[^"]*"
  • Repeat [^"]*"[^"]*" any amount of times
"[^"]*"(?:[^"]*"[^"]*")*

See this demo at regex101 (the \n in multiline demo is for staying in line)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading