Python regex: how to replace string except if another string exist on the same line? -


i fixing spell of articles withreplace.pyby replacing "choeur" "chœur".
there file links in mediawiki syntax :

[[fichier:menditte (pyr-atl, fr) choeur de l'église.jpg|thumb|chœur de l'église]] 

editing kind of thing broke link. can't use [] because there's 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 case, spell should fixed.
need not edit if there is.jpgon same line , after "choeur".

my problem couldn't find way handle boolean expressions inside python regex

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

pattern:

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

replacement:

$1œ$2 

about word boundaries:

word boundaries used delimite letters \bchoeurs?\b or \.jpg\b, , job in cases. however, keep in mind word boundaries not work string: __choeur__. if needed, word boundaries can replaced lookarounds, example:

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


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -