LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 03-13-2017, 04:24 PM   #1
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Rep: Reputation: Disabled
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.
 
Old 03-13-2017, 07:02 PM   #2
rarog
LQ Newbie
 
Registered: May 2016
Distribution: Slackware
Posts: 13

Rep: Reputation: Disabled
\d is regex in Perl notation try:
Code:
ip addr | grep -P "^\d{1}"
 
1 members found this post helpful.
Old 03-13-2017, 07:05 PM   #3
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
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 07:11 PM.
 
Old 03-13-2017, 10:20 PM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Not a man page but a web page, here: https://www.gnu.org/software/finduti...ar-Expressions

HTH
 
Old 03-14-2017, 05:58 AM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,603

Rep: Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361
additionally you can try to check this: http://www.pcre.org/, especially: http://www.pcre.org/current/doc/html/pcre2grep.html and/or http://www.pcre.org/current/doc/html/pcre2pattern.html
 
Old 03-14-2017, 06:16 AM   #6
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,463
Blog Entries: 3

Rep: Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230Reputation: 2230
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.
Old 03-14-2017, 11:21 AM   #7
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
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?
 
Old 03-15-2017, 04:34 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,603

Rep: Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361
you can always reach it here: https://linux.die.net/man/7/regex
the mentioned man page is part of the package manpages
http://packages.ubuntu.com/search?su...rchon=contents
 
Old 03-15-2017, 07:35 AM   #9
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
you can always reach it here: https://linux.die.net/man/7/regex
the mentioned man page is part of the package manpages
http://packages.ubuntu.com/search?su...rchon=contents
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.
 
Old 03-16-2017, 03:04 AM   #10
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,603

Rep: Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361
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.
Old 03-16-2017, 12:00 PM   #11
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
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?
 
Old 03-16-2017, 12:11 PM   #12
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179Reputation: 3179
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 12:18 PM.
 
Old 03-16-2017, 12:44 PM   #13
fanoflq
Member
 
Registered: Nov 2015
Posts: 397

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
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?
 
Old 03-16-2017, 12:48 PM   #14
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,603

Rep: Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361Reputation: 4361
Quote:
Originally Posted by fanoflq View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Confusing issue with Perl regEx - Regex check seems to require variable being set EnderX Programming 1 09-07-2013 05:36 AM
LXer: OpenOffice versus LibreOffice versus The World LXer Syndicated Linux News 0 03-06-2013 12:30 AM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 02:10 AM
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 09:08 PM
[SOLVED] bash - versus --perl - versus python ow1 Linux - Software 2 05-03-2010 08:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration