regex - replacing all behind my matched string - gsub -
i'm new string manipulations in r. have case in i'm using several matched replacements in foor loop, , has rely on gsub.
now have string (illustrative example), "today great day"
in want use pattern "today is" only, , replace "my value"
but metacharacters need select rest of string?
my try
gsub("today is+.", "my value", myobject)
now selects 1 value after "today is", how can make run way?
use capture-class grouping parens in pattern, , refer them \\<n>
in replacement, , think need swap order of .+
in pattern:
> gsub("(today is)(.+)", "my value\\2", "today great day") [1] "my value great day"
Comments
Post a Comment