Problem with a field in RegEX

1

I have the following expression:

(?!.*");

It captures anything separated by the ; character except when it is within 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 in the list:

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

And what is returned are the semicolons 1 and 3 . Where is the error? How do I solve it? I prefer the shared response with the .NET Framework

    
asked by anonymous 13.07.2015 / 00:25

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 the DotnetFiddle

    
14.07.2015 / 00:22