samedi 24 janvier 2015

Is replacing certain words with certain adjectives better by regex or pure Python?


I wonder if the following can be done reliably by regex, or should I stick to plain string manipulation in Python? Performance is very important.



German apple is good. Apple is nice. Where is the apple? English apple have worms. English people are nice.




  • I would like to replace all occurrences of Apple or apple with German apple.

  • However if apple has the adjective English, English should be replaced by German.

  • English people won't change, because people aren't apples.


I am not really an expert in regex. There are some online generators, such as this http://www.regexr.com/


I tried this and it gives me only the first apple. \b(apple)


Any help would be much appreciated





Aucun commentaire:

Enregistrer un commentaire