Need to know about the function of \(\)
in grep("-(mean|std)\(\)", x[,2])
1 Answer
This matches (
and )
literally.
()
is used as capturing groups in Extended Regular Expressions (as used by r
's grep()
or the grep
command with the -E
option) or Perl Compatible Regular Expression which extend Extended Regular Expressions (as used by r
's grep(..., perl=TRUE)
or some grep
commands with the -P
option).
Hence to match ()
literally, \
is used.
-
-
So to match a pattern "-mean() or std()" we add "\(\)" in grep. right? Jun 19, 2015 at 7:46
-
@RishabhVerma i have added explaination. Hope it helps. If you need more do tell. Jun 19, 2015 at 7:46
-
@RishabhVerma Yes to match "-match()" or "-std()" you need to add "()" Jun 19, 2015 at 7:47
-
@RishabhVerma You can accept the answer if you think it is correct and you are satisfied. This helps other in reading answers. Jun 19, 2015 at 7:48