Regular expression, string search contains but does not start with

I am working on parsing a text file that goes through each line, and I'm having trouble finding Regex. Part of this analysis involves changing events such as:

& Eacute; to & eacute;

I tried the following regular expression but returns nothing:

/^(?!&)(É)/

Any suggestions?

+3
source share
3 answers

So, you want to combine Éonly if it is not at the beginning of the line?

Using

/(?<=.)&Eacute;/

(assuming Ruby 1.9 because 1.8 does not support lookbehind)

Rationale: .Matches any character except a newline. Therefore, if the lookbehind statement matches, we are not at the beginning of the line.

+5

Ruby 1.9, lookbehind :

t.gsub! /(?<=.)&Eacute;/, '&eacute;'

Ruby 1.8 - :

while t =~ /(.)&Eacute;/
    t.sub! /(.)&Eacute;/, "#{$1}&eacute;"
end

t - , .

+2

If you want to combine &Eacute;lines anywhere, but not in the first position:

/^.+(&Eacute;)/

This is consistent, for example "abc&Eacute;def", but not"&Eacute;"

UPDATE: fixed bugs marked with tim

0
source

All Articles