Regular expressions are in much more widespread use than merely R... and there
are correspondingly more resources for learning than just R-help. Please do
make use of them. Here are a couple that googling "regex character set carat"
found:
https://www.regular-expressions.info/charclass.html
htt
A quick question.
Could you please explain the -- [^}]* -- part in finding the pattern?
On Fri, Sep 13, 2019 at 12:19 AM Bert Gunter wrote:
>
>
> You can't use the same regex for str_extract_all as I used for sub (or gsub,
> which is what is required here)! If you do this sort of thing a lot, y
Awesome, thanks!
On Fri, Sep 13, 2019 at 12:19 AM Bert Gunter wrote:
>
>
> You can't use the same regex for str_extract_all as I used for sub (or gsub,
> which is what is required here)! If you do this sort of thing a lot, you
> *must* learn more about regex's.
>
> Anyway, this will do what you
You can't use the same regex for str_extract_all as I used for sub (or
gsub, which is what is required here)! If you do this sort of thing a lot,
you *must* learn more about regex's.
Anyway, this will do what you want I think:
z <- paste("ab{cd$ }ed", "ab{cad$ }ed", collapse = " ") ## just for
r
Thanks Bert,
This works, but if in my text there are more than one patterns then
fails to generate desired result.
library(stringr)
str_extract_all(paste("ab{cd$ }ed", "ab{cad$ }ed", collapse = " "),
".*(\\{.*\\}).*")
This generates below -
[[1]]
[1] "ab{cd$ }ed ab{cad$ }ed"
I was expecting I
> 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.
Be
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
7 matches
Mail list logo