Matching regex in the right direction

Usually we use regular expression matching from left to right. I want to know if there is any switch that can be used to match from right to left in Python? Or is this feature built into any other language?

eg

abcd1_abcd2

If a regular expression is specified abcd, it will match two lines abcd. What I want is to put the last match first, thus matching in the opposite direction.

+4
source share
1 answer

You can undo the list suggested by @SilentGhost:

import re

for s in reversed(re.findall('abcd.', 'abcd1_abcd2')):
    print s
+3
source

Source: https://habr.com/ru/post/1769970/


All Articles