[Solved] Translate regular expression to python


You can use the Regex pattern:

(?:[A-Za-z.]*/PERSON\s*)+
  • [A-Za-z.]* matches zero or more of [A-Za-z.]

  • /PERSON\s* matches /PERSON followed by zero or more whitespace

  • The above is put in a non-captured group and the group is matched one or more time by the + token.

Example:

In [9]: re.search(r'(?:[A-Za-z.]*/PERSON\s*)+', 'Leo/PERSON Messi/PERSON hello').group()
Out[9]: 'Leo/PERSON Messi/PERSON ' 

0

solved Translate regular expression to python