Jump to content

ReguIar expression Apostrophe '


Recommended Posts

Is there a way to find an ' in a regular expression apart from [[:punct:]]

 

I want to check a number of files for correct use of s' and 's

 

\' doesn't work but [[:punct:]] does but I can't make the ? operator work when using it. Any thoughts out there?

 

egrep -o '[A-Za-z]*s[[:punct:]]|[A-Za-z]*[[:punct:]]s' filename

 

is currently working for me but it seems incredibly clumsy.

Edited by willisoften
Link to comment
Share on other sites

' should work. If it does not, it probably is because of bad quoting. Remember that in bash, nothing can be quoted inside single quotes, not even single quotes themselves. You should try that (note the external double quotes instead of single quotes):

egrep -o "[A-Za-z]*s'|[A-Za-z]*'s" filename

Yves.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...