Linux - Newbie This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
03-13-2017, 03:24 PM
|
#1
|
Member
Registered: Nov 2015
Posts: 397
Rep: 
|
regex on \d versus [0-9]
#This grep regex produces no output using \d for digit:
Code:
$ ip addr | egrep -i "^\d{1}"
#This grep regex produces output using [0-9] for digits:
Code:
$ ip addr | egrep -i "^[0-9]{1}"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
2: enp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
3: wlp2s0b1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
What did I missed on the first egrep regex pattern?
Thank you.
|
|
|
03-13-2017, 06:02 PM
|
#2
|
LQ Newbie
Registered: May 2016
Distribution: Gentoo
Posts: 19
Rep: 
|
\d is regex in Perl notation try:
Code:
ip addr | grep -P "^\d{1}"
|
|
1 members found this post helpful.
|
03-13-2017, 06:05 PM
|
#3
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Thank you.
Is there a list of extended regex special characters in man page somewhere besides "Pattern Matching" in man bash?
Last edited by fanoflq; 03-13-2017 at 06:11 PM.
|
|
|
03-13-2017, 09:20 PM
|
#4
|
Member
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792
|
|
|
|
03-14-2017, 04:58 AM
|
#5
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,351
|
|
|
|
03-14-2017, 05:16 AM
|
#6
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
If you're talking about general POSIX regex and POSIX extended regex, then there is manual page for that. There is also a manual page for the Perl regular expressions.
Code:
man 7 regex
man perlre
Both should be on your system already. The Perl pattern matching is well worth becoming familiar with, not only is it very common (often known as PCRE or Perl-Compatible Regular Expressions) but it is very, very useful.
|
|
1 members found this post helpful.
|
03-14-2017, 10:21 AM
|
#7
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by Turbocapitalist
If you're talking about general POSIX regex and POSIX extended regex, then there is manual page for that. There is also a manual page for the Perl regular expressions.
Code:
man 7 regex
man perlre
Both should be on your system already. The Perl pattern matching is well worth becoming familiar with, not only is it very common (often known as PCRE or Perl-Compatible Regular Expressions) but it is very, very useful.
|
On centOS 7, minimal install, I could not find it.
Code:
># man -k regex
regexp_table (5) - format of Postfix regular expression tables
Tie::Hash::NamedCapture (3pm) - Named regexp capture buffers
Which package provides man 7 regex?
|
|
|
03-15-2017, 06:35 AM
|
#9
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by pan64
|
Code:
[root@Centos7-1024ram-minimal ~]# yum list all | grep -i regex
ant-apache-regexp.noarch 1.9.2-9.el7 base
boost-regex.i686 1.53.0-26.el7 base
boost-regex.x86_64 1.53.0-26.el7 base
perl-PPIx-Regexp.noarch 0.034-3.el7 base
perl-XML-RegExp.noarch 0.04-2.el7 base
regexp.noarch 1.5-13.el7 base
regexp-javadoc.noarch 1.5-13.el7 base
No regex.7.* package in yum repositories.
|
|
|
03-16-2017, 02:04 AM
|
#10
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,351
|
regex.7.gz is the man page itself, manpages is the name of the package - but it is on ubuntu. Looks like the name of the package on CentOS is: man-pages
|
|
1 members found this post helpful.
|
03-16-2017, 11:00 AM
|
#11
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by pan64
regex.7.gz is the man page itself, manpages is the name of the package - but it is on ubuntu. Looks like the name of the package on CentOS is: man-pages
|
Thank you.
Where did you find this information locally, on your computer?
|
|
|
03-16-2017, 11:11 AM
|
#12
|
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 11,262
|
The difference ... is ... Unicode.
Here's a paragraph that might be relevant, from Perl's perldoc perlre: (emphasis mine)
Quote:
Unlike most locales, which are specific to a language and country pair, Unicode classifies all the characters that are letters somewhere in the world as "\w". For example, your locale might not think that "LATIN SMALL LETTER ETH" is a letter (unless you happen to speak Icelandic), but Unicode does.
Similarly, all the characters that are decimal digits somewhere in the world will match "\d"; this is hundreds, not 10, possible matches. And some of those digits look like some of the 10 ASCII digits, but mean a different number, so a human could easily think a number is a different quantity than it really is. For example, "BENGALI DIGIT FOUR" (U+09EA) looks very much like an "ASCII DIGIT EIGHT" (U+0038). And, "\d+", may match strings of digits that are a mixture from different writing systems, creating a security issue. [...] The "/a"modifier can be used to force "\d" to match just the ASCII 0 through 9.
|
Perl's implementation of regular expressions is a de facto standard, duplicated by most other languages, therefore this discussion should be directly relevant.
See also a discussion of so-called "POSIX bracket expressions" (N.B. not "character classes" ...) e.g. here. Particularly, in this case, [:digit:].
Last edited by sundialsvcs; 03-16-2017 at 11:18 AM.
|
|
|
03-16-2017, 11:44 AM
|
#13
|
Member
Registered: Nov 2015
Posts: 397
Original Poster
Rep: 
|
Quote:
Originally Posted by sundialsvcs
The difference ... is ... Unicode.
Here's a paragraph that might be relevant, from Perl's perldoc perlre: (emphasis mine)
Perl's implementation of regular expressions is a de facto standard, duplicated by most other languages, therefore this discussion should be directly relevant.
See also a discussion of so-called "POSIX bracket expressions" (N.B. not "character classes" ...) e.g. here. Particularly, in this case, [:digit:].
|
Since perl is a defacto standard, does all commands
allow for perl regex?
|
|
|
03-16-2017, 11:48 AM
|
#14
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,351
|
Quote:
Originally Posted by fanoflq
Where did you find this information locally, on your computer?
|
for ubuntu and debian there is a package search page (what I linked), so that will easily tell you the name of the package. But obviously you can look around on your own pc.
for centos you can try here: https://www.centos.org/docs/5/html/y...-packages.html, but probably better to try here: http://rpm.pbone.net/index.php3/stat/2/simple/1
|
|
|
All times are GMT -5. The time now is 09:28 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|