regex - Extracting Text in R from checkbox sort of format -
i have text following:
x<-"annual turnover in crores ( )15-25lacs ( )25-50 lacs ( )50-75 lacs ( )75lacs 1 cr ( x ) 1-10 cr ( )10-25cr ( )25-50cr ( )above 50 crs" now can see there's check before 1-10 cr box. how can r extract value has box checked?
i using
a<-sub("..\(x).",x)
you can achieve want through simple pattern in regex:
regmatches(x,regexpr("(?<=\\( x \\))[^\\(]+",x,perl=true)) #[1] " 1-10 cr " here how pattern build.
the
(?<=something)tells part of string aftersomething. in case, want after( x ). since()symbols special characters in regex, had escape them thorugh\\.the
[^\\(]+part tells characters not(. because next "checkbox" value starts(. again, had escape symbol.the
perl=trueargument needed, otherwise behind defined @ start of pattern won't valid.
hope clarifies little.
Comments
Post a Comment