I have the following string type,
abc - xyz
abc - pqr - xyz
abc - - xyz
abc - pqr uvw - xyz
I want to get text xyzfrom the 1st line and pqrfrom the second line, `` (empty) from the 3rd and pqr uvw. The second hyphen is optional. abc- a static string, it should be there. I tried the following regular expression,
/^(?:abc) - (.*)[^ -]?/
But he gives me the following conclusion,
xyz
pqr - xyz
- xyz
pqr uvw - xyz
I do not need the last part in the second line. I use perl to create scripts. Can this be done using regex?
source
share