ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Problems with '+' in grep
I am trying to valdiate an e-mail address. There are zillions of examples out on the internet, but whatever I use, my valid e-mail address is never validated.
It appears to boil down at the '+' character. For example when I try to match zero or more alpha characters I get a match:
I don't get that, what I am asking is "match one or more alpha characters at the beginning of the string". Or am I?
I am using GNU grep 2.5.1
Obviously the real matching regexp is much more complicated, but since I even don't understand this simple example, it is unthinkable that I could use those.
I am not an expert about regular expressions, but from the grep man page
Quote:
In basic regular expressions the metacharacters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).
also I'd use the boundary tag \b which matches the empty string at the edges of a word, as in
bigearsbilly, sorry but I didn't see your post before posting mine (just for a bunch of minutes), anyway I tried the expression from the OP with egrep and it doesn't work on my system:
Fedora Core 5, 2.6.20-1.2316.fc5, grep 2.5.1. Instead the one suggested by ghostdog74 works. But - I repeat - I am not a regexp guru, so I leave the correct explanation to you.
bigearsbilly, sorry but I didn't see your post before posting mine (just for a bunch of minutes), anyway I tried the expression from the OP with egrep and it doesn't work on my system:
egrep is the same as grep -E.
...
-E, --extended-regexp
Interpret PATTERN as an extended regular expression (ERE, see
below). (-E is specified by POSIX.)
...
-e PATTERN, --regexp=PATTERN
Use PATTERN as the pattern. This is useful to protect patterns
beginning with hyphen-minus (-). (-e is specified by POSIX.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.