Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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 testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Rep:
Anything in square brackets means list or range. [0-9] means any single integer 0 thru 9 inclusive. [12345] means any combination of one or more in the list. I think the "\+" might produce no output. But this exercise is so mundane I can only hope it's a class assignment and not actual on-the-job stuff.
You might want to change the quotes from double to single.
Last edited by AwesomeMachine; 08-23-2017 at 05:52 AM.
\+ is one of these questionable BRE extensions in Linux.
Clear and portable is \{1,\} or + in egrep (or grep -E that uses ERE).
It means the preceding character(-wildcard) must exist 1 or more times.
\+ is one of these questionable BRE extensions in Linux.
Clear and portable is \{1,\} or + in egrep (or grep -E that uses ERE).
It means the preceding character(-wildcard) must exist 1 or more times.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by MadeInGermany
\+ is one of these questionable BRE extensions in Linux.
Clear and portable is \{1,\} or + in egrep (or grep -E that uses ERE).
It means the preceding character(-wildcard) must exist 1 or more times.
I knew that as well [0-9]+ matches one or more [0-9]. Just like an '*' matches zero or more.
But why the '\' in front of \+? That would indicate a literal '+', wouldn't it?
I use [0-9]+ and [0-9]{3} quite often, but I was looking forward to an answer to [0-9]\+
In ERE (extended regular expression) the special meaning is {m,n} and +
In BRE (basic regular expression) the special meaning is \{m,n\}
Someone thought it makes sense to have \+ in BRE following the same logic. This is in newer Linux only; it is not in the standards.
Also some take-overs from PRE (Perl regular expression, highly compatible with ERE) went into newer Linux BRE and ERE, like \b \s \d I wouldn't use them: no standard, not portable.
Instead use
\< \> (left and right word boundary, quite portable in BRE but also no standard)
[[:space:]]
[0-9] or [[:digit:]]
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
I knew there were some differences in syntax between BRE and ERE. I always thought ERE was an extension of BRE and upward compatible. Not so. That backslashes have an opposite effect in some situations in BRE and ERE I never knew. Never too old to learn.
I knew there were some differences in syntax between BRE and ERE. I always thought ERE was an extension of BRE and upward compatible. Not so. That backslashes have an opposite effect in some situations in BRE and ERE I never knew. Never too old to learn.
jlinkels
Not so. Yes, you are right. And it is valid not only for grep, but for sed too.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.