If I have, say, the string,
txt = "now is the time for all (good) men"
then I want to remove the substring beginning with "for" and ending at the end of the string, namely, remove:
subtext = "for all (good) men"
I do realize that an expression of the form StringReplace[txt, regex ->""]
or StringReplace[txt, pattern->""]
will do it, but I don't know what regular expression or pattern to use.
The part of the substring to be omitted definitely begins with the specific text "for", but anything could follow it.
StringReplace[txt, "for" ~~ ___ -> ""]
$\endgroup$ – paw Oct 26 '15 at 0:21"for" ~~ ___ ~~ EndOfString
. You can see the corresponding regular expression usingStringPattern`PatternConvert
. In this case it is(?ms)for.*\z
. $\endgroup$ – Oleksandr R. Oct 26 '15 at 0:22~~~ EndOfSting
? $\endgroup$ – murray Oct 26 '15 at 0:24