> sub(".*(\\{.*\\}).*", "\\1","ab{cd$ }ed") [1] "{cd$ }"
Use ".+" instead of ".*" within the {} if you don't want to return empty {}'s. You might wish to use the stringr package for string matching and manipulation, as it provides a more user friendly and consistent interface to these tasks. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Sep 12, 2019 at 9:31 AM Christofer Bogaso < bogaso.christo...@gmail.com> wrote: > Hi, > > I am wondering on what is the correct way to select a pattern which goes > as - > > {"(any character with any length)"} > > The expressions " {" " and " "} " both are included in the pattern. > > For example, the lookup of the above pattern in the text " > {"asaf455%"}57573blabla " will result in {"asaf455%"} > > Any help will be highly appreciated. > > Thanks, > > ______________________________________________ > 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. > [[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.