Home > database >  regular expression not finding all the patterns in a string
regular expression not finding all the patterns in a string

Time:09-15

I am using Python regex to find a pattern with pipes "|" enclosing any number of asterics. for example, my program should return | ** | or | * | or | *** | etc.

I created this regular expression below. But it seems to miss few of the patterns in the substring.

import re
pat = r"\|\* \|"
string = "*|**|*|***|**"
print(re.findall(pat,string))

I am getting this output

  • Related