-1

I have tried to write a regular expression for the an example code to use in grep search.

My requirement is to get string output that matches only the below

execute(any word here)

For eg.

execute(any)
execute(math)

and the results should not output

execute("any")
execute("math")

I already tried the following, but the problem with this is that it outputs everything and doesn't give me the required solution.

grep -E '^execute\(*([^)]+)*\)'

I expect my output to be execute(math) or execute(s) and not

execute("math") or execute("s")

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
user1753356
  • 131
  • 1
  • 3

1 Answers1

0

Based on your limited sample data, this should work:

^execute\([a-zA-Z]+\)$

https://regex101.com/r/S4owrs/2

MonkeyZeus
  • 20,375
  • 4
  • 36
  • 77
  • Thanks very much for the solution ! it worked, but somehow i couldn't make it work on my terminal `grep -E '^execute\([a-zA-Z]+\)$'` by typing just that. This `grep execute\([a-zA-Z] *.lib` somehow got me closer to what i wanted. Anyways appreciate your time. Do you have any idea why the first version didn't work ? – user1753356 Aug 14 '19 at 22:39
  • @user1753356 I'm not sure I don't have a Linux box to test with. Try it with the `-E` option for extended regexp. You can also try simply removing the anchors `^` and `$` and see if that makes a difference. It's possible you need `pcregrep` per https://stackoverflow.com/q/152708/2191572. Above all else I suggest reading the man pages for whatever tool you use. – MonkeyZeus Aug 14 '19 at 23:03
  • Awesome, your link was really helpful !! i tried this `find . -iname '*.lib' | xargs pcregrep -M 'execute\([a-zA-Z]+\)'` from the link you shared and it worked ! Have a nice day! :) – user1753356 Aug 15 '19 at 09:41
  • @user1753356 You're welcome, I'm glad you found my post and comments useful! – MonkeyZeus Aug 15 '19 at 11:53