I am trying to match the following regex :
((symbol_live:)\s+\"(?P<LiveSymbol>.)\")?((symbol_dead:)\s+\"(?P<DeadSymbol>.)\")?(gamefield:\s*\n\"\n(?P<Seed>(((\g<DeadSymbol>)|(\g<LiveSymbol>))+\n)+)\"\s*)?
the given string to search in is :
gamefield:
"
-------------------------------
-------------------------------
----------oo-------------------
----------oo-------------------
------------oo-----------------
------------oo-----------------
-------------------------o-----
-------------------------o-----
-------------------------o-----
-------------------------------
-------------------------------
-------------------------------
-------------------------------
"
symbol_dead: "-"
symbol_live: "o"
I am writing this with python RE module and I used finditer to iterate through all the possible matches.
it returns both symbol_dead: "-" and symbol_live: "o" but not the "seed" named group in gamefield
I write the following code to return the value for each group in the iteration:
p = re.finditer(r'((symbol_live:)\s+\"(?P<LiveSymbol>.)\")?((symbol_dead:)\s+\"(?P<DeadSymbol>.)\")?(gamefield:\s*\n\"\n(?P<Seed>(((\\g<DeadSymbol>)|(\\g<LiveSymbol>))+\n)+)\"\s*)?', string=input, flags=re.M)
for l in p:
if 'DeadSymbol' in l.groupdict().keys() and l.groupdict()['DeadSymbol'] != None:
print('DeadSymbol return = ' + l.groupdict()['DeadSymbol'])
elif 'LiveSymbol' in l.groupdict().keys() and l.groupdict()['LiveSymbol'] != None:
print('LiveSymbol return = ' + l.groupdict()['LiveSymbol'])
elif 'Seed' in l.groupdict().keys() and l.groupdict()['Seed'] != None:
print('Seed return = ' + l.groupdict()['Seed'])
When I check this in https://regexr.com/ it works! but not works in https://pythex.org/
I don't know what is wrong with the regex and I need help on this! since it is becoming frustrating for me to resolve!
symbol_dead: "-". regex101.com/r/fsCfF7/1(?: ).