What is the email matching regex in basic regex for grep?

I created a text file and put some email addresses in it. Then I used grep to find them. Indeed it worked:

# pattern="^[a-zA-Z0-9]<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="577c17">[email protected]</a>[a-zA-Z0-9]+.[a-z]{2,}"
# grep -E $pattern regexfile

but only as long I kept the -E option for an extended regular expression. How do I need to change the above regex in order to use grep without -E option?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Be aware that matching email addresses is a LOT harder that what you have. See
an excerpt from the Mastering Regular Expressions book

However, to answer your question, for a basic regular expression, your quantifiers need to be one of *, + or {m,n} (with the backslashes)

pattern='^[a-zA-Z0-9]<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddf69d">[email protected]</a>[a-zA-Z0-9]+.[a-z]{2,}'
grep "$pattern" regexfile

You need to quote the pattern variable


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x