Regex newbie here. I need to create a regex expression that will support following strings:
<optional constant string 1><string 2><space><string 3>
Here constant string 1 is: ad_
Ex (allowed patterns).
[1]
ad_xyz.qwe.sty blah blah...
string 1: ad_
string 2: xyz.qwe.sty
string 3: blah blah... (free text)
[2]
abc blah ...
string 1: (absent)
string 2: abc
string 3: blah ... (free text)
[3]
sdf.pqr blah blah blah...
string 1: (absent)
string 2: sdf.pqr
string 3: blah blah blah... (free text)
Here is what I'm doing:
(?:[ad_]{0,1})?\-[a-zA-Z.]*\.[a-zA-Z0-9]*
Now this detects only first pattern. Though I have mentioned {0,1}, still string 1 is mandatory.
[ad_]matches one ofa,d, or_. If you want to match the whole string it’d bead_;(?:ad_)?matchesad_zero or one time.