in reply to Re: Capturing everything after an optional character in a regex?
in thread Capturing everything after an optional character in a regex?
If X is there I want everything after the X. If X is not there I want the whole string.Try this on a copy of the string:
This will only substitute everything upto the first X, if one exists. It'll not change the string if it doesn't.s/^.*?X//;
Drop the question mark if you want to locate the last "X".
And if the string can contain newlines, add the /s modifier, which changes the matching behaviour of /./ to possibly match a newline as well.
|
|---|