regex - Regular Expression for matching word -
this may easy reason unable expression. want find position/index of matching words in given string. example
"this , nand xor nor aatd". now, want find index of matching string starting , can have char between a-z must end t or d. result should [9,and][14,and][24,aat][25,atd]
my expression (?s)(a.[td]) missing last index. in advance. using python.
if trying using regular expression, need positive lookahead assertion. replaced dot in regular expression [a-z]
since stated want match word characters.
>>> import re >>> p = re.compile(r'(?=(a[a-z][td]))') >>> m in p.finditer('this , nand xor nor aatd'): ... print [m.start() + 1, m.group(1)] [9, 'and'] [14, 'and'] [26, 'aat'] [27, 'atd']
Comments
Post a Comment