I have this piece of code:
for n in (range(1,10)):
new = re.sub(r\'(regex(group)regex)?regex\', r\'something\'+str(n)+r\'\\1\', old, count=1)
I looked at this again.
A note that it is unfortunate that you have to deal with NULL's,
but here are the rules you must follow.
The below matches all successfully match nothing.
You have to do this to find out the rules.
It's not as simple as you may think. Take a close look at the results.
There is no apparent steadfast way formwise to tell if you will get NULL or EMPTY.
However, looking at it closer, the rules come out and are fairly simple.
These rules must be followed if you care about NULL.
There are only Two rules:
Rule # 1 - Any code GROUP that can't be reached, will result in NULL
(? # (1 start)
(? a )? # (2)
(? b? ) # (3)
)? # (1 end)
|
(? # (4 start)
(? c? ) # (5)
(? d? ) # (6)
) # (4 end)
** Grp 0 - ( pos 0 , len 0 ) EMPTY ** Grp 1 [Alt_1] - ( pos 0 , len 0 ) EMPTY ** Grp 2 [a] - NULL ** Grp 3 [b] - ( pos 0 , len 0 ) EMPTY ** Grp 4 [Alt_2] - NULL ** Grp 5 [c] - NULL
Rule # 2 - Any code GROUP that can't be matched on the INSIDE, will result in NULL
(? # (1 start)
(? a? ) # (2)
)? # (1 end)
(? # (3 start)
(? a )? # (4)
)? # (3 end)
(? # (5 start)
(? a ) # (6)
)? # (5 end)
(? # (7 start)
(? a )? # (8)
) # (7 end)
** Grp 0 - ( pos 0 , len 0 ) EMPTY ** Grp 1 [A_1] - ( pos 0 , len 0 ) EMPTY ** Grp 2 [a1] - ( pos 0 , len 0 ) EMPTY ** Grp 3 [A_2] - ( pos 0 , len 0 ) EMPTY ** Grp 4 [a2] - NULL ** Grp 5 [A_3] - NULL ** Grp 6 [a3] - NULL ** Grp 7 [A_4] - ( pos 0 , len 0 ) EMPTY ** Grp 8 [a4] - NULL