Hi All: I have a regular expression problem. If a character string ends
with "rhofixed" or "norhofixed", I want that part of the string to be
removed. If it doesn't end with either of those two endings, then the
result should be the same as the original. Below doesn't work for the
second case. I know why but not how to fix it. I lookrd st friedl's book
and I bet it's in there somewhere but I can't find it. Thanks.

s <- c("lngimbintrhofixed","lngimbnointnorhofixed","test")

result <- sub("^(.*)([n.*|r.*].*)$","\\1",s)

 print(result)
[1] "lngimbint"     "lngimbnointno" "test"

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to