I'm trying to match a string with an optional part in the middle.
Example strings are:
20160131_abc.pdf
20160131_abc_xx.pdf
20160131_def.pdf
The result should include the name of the file (w/o the optional _xx).
What I have so far:
/[0-9]{8}_(abc(_xx)?|def)\.pdf/i
This kind of works but will return the name as abc_xx for the second string - I only want the abc part of it. Is it somehow possible to ignore the subgroup?
my_string = my_string.replace("_xx", "");do the job?[0-9]{8}_(abc|def(?=\.pdf))(?:_xx)?\.pdf