Problem with a field in Regex

Asked

Viewed 32 times

1

I have the following expression:

(?!.*");

it captures anything that is separated by the character ; except when ta inside a string. Here’s an example:

ABC;            #captura o último ;
123;            #captura o último ;
"XYZ";          #captura o último ;
"A B; C";       #captura apenas o último ; não o que está dentro da string
"Uma string     #
 com ; várias   #esse aqui é capturado
 linhas;";      #captura o último ;

Let’s look at this last item on the list:

"Uma string
 com ;(1) várias
 linhas;(2)";(3)

And what is returned are the semicolons 1 and 3. Where’s the bug? How do I fix? I prefer the answer with the . NET Framework

  • These examples are what the regex ago or what should do? First you say that regex captures "anything that is separated by the character ;", but then you say the regex only captures the ;. Try to explain better what happens now and what you want it to happen.

  • These examples are showing that he did

1 answer

1


What you are looking for is the parameter RegexOptions.Singleline, with this parameter the regular expression is interpreted as a single line.

Regex.Matches(input, "(?!.*\");", RegexOptions.Singleline)

I made an example in Dotnetfiddle

Browser other questions tagged

You are not signed in. Login or sign up in order to post.