Ruby – Regular expression, look for strings that include but not starting with strings

I am parsing a text file, traversing each line, and I am having trouble finding regular expressions. Part of this parsing involves changes appearing, for example:

& Eacute; and & eacute;

I tried the following regular expression, but it does not return anything:

 /^(?!&)(É)/

Any suggestions?

So you want to match & Eacute; only if it is not online at the beginning?

Use

/(?<=.)É/

(Assuming Ruby 1.9 because 1.8 does not support lookbehind)

Reason: Match any character except the newline character. Therefore, if the lookbehind assertion matches, we are not at the beginning of the line.

< p>I'm parsing a text file, looping through each line, and I'm having trouble finding regular expressions. Part of this parsing involves changes appearing, for example:

& Eacute; And & eacute;

I tried the following regular expression, but it does not return anything:

/^(?!&)(É ;)/

Any suggestions?

So you want to match & Eacute; only if it is not online at the beginning?

Use

/(?<=.)É/

(Assuming Ruby 1.9 because 1.8 does not support lookbehind)

Reason: Match any character except the newline character. Therefore, if the lookbehind assertion matches, we are not at the beginning of the line.

Leave a Comment

Your email address will not be published.