How to use quotation mark in grep range query

30 views Asked by At

How to find (f' or (f" or (" or (' with grep?

For example the regex could be (f\?["'] but how to pass this to grep - it can't be surrounded by quotation marks neither by apostrophes?

1

There are 1 answers

0
The fourth bird On BEST ANSWER

This pattern in your question f\?["'] matches an f char followed by ? and one of " or '

If the text is for example in file, you might use:

grep -Eo "(\(|\bf)['\"]" file

The pattern matches:

  • ( Start group
    • \( Match (
    • | Or
    • \bf A word boundary followed by matching f
  • ) Close the group
  • ['\"] Match either ' or "

Output

f'
f"
("
('