1

I am fixing the spell of some articles withreplace.pyby replacing "choeur" by "chœur".
There are also file links in the mediawiki syntax :

[[Fichier:Menditte (Pyr-Atl, Fr) choeur de l'église.JpG|thumb|Chœur de l'église]]

Editing that kind of thing will broke the link. I can't use [] because there's also the link description :

[[Fichier:JeronimosRoyalTombs.Jpg|thumb|right|Tombeaux de [[Jean III de Portugal]] (à gauche) et de [[Catherine de Castille]] (à droite) dans la choeur de l'église]]

In that case, the spell should be fixed.
So I need to not do the edit if there is.jpgon the same line and after "choeur".

My problem is I couldn't find the way to handle boolean expressions inside python regex

the
  • 21,007
  • 11
  • 68
  • 101
user2284570
  • 2,891
  • 3
  • 26
  • 74

1 Answers1

1

You can use a negative lookahead (?!...) (not followed by):

pattern:

(?i)\b(ch)oe(urs?\b)(?!.*\.jpg\b)

replacement:

$1œ$2

About word boundaries:

Word boundaries are used to delimite letters for \bchoeurs?\b or \.jpg\b, and would do the job in most cases. However, keep in mind that the word boundaries will not work with this string: __choeur__. If needed, word boundaries can be replaced with lookarounds, example:

(?:(?<=_)|\b)choeurs?(?=_|\b)

Casimir et Hippolyte
  • 88,009
  • 5
  • 94
  • 125