Rafael Minuesa
Rafael Minuesa

Reputation: 27

Using Regex in Notepad++, how do I select only the period inside some specific lines but not inside others

Using Regex in Notepad++, how do I select only the period inside these lines:

<div class="english">One. Two. Three. Four. Five.</div>

but leaving alone the period inside these ones:

<div class="spanish">Uno. Dos. Tres. Cuatro. Cinco.</div>

Thanks

Upvotes: 0

Views: 76

Answers (2)

Robin
Robin

Reputation: 9644

If you want to select only the dots between <div class="english"> and </div> you can use:

(?:<div class="english">|(?!^)\G)(?:[^.<]|<(?!/div>))*\K\.

Explanation and demo:

(?:                     # non-capturing group
  <div class="english"> # our delimiter
|                       # or
  (?!^)\G               # the end of the last match
)
(?:
  [^.<]               # any character except '.' or '<' (even newline)...
|                     # or ...
  <(?!/div>)          # '<' not followed by a '/div>'
)*
\K                    # leave what we found so far out of the match
\.                    # match the dot

See reference for the use of \K and \G.

Upvotes: 2

vks
vks

Reputation: 67988

<div class="(?!english)[^"]*">.*?<\/div>\K|\.(?=.*?<\/div>)

You can do this using \K.See demo.

https://regex101.com/r/cT0hV4/18

Upvotes: 1

Related Questions