Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Perl: /^(?:(d+)|::)* what does that equate to?

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
macawgumbo
Apprentice
Apprentice
Posts: 165
Joined: Fri May 28, 2004 1:12 am

Perl: /^(?:(d+)|::)* what does that equate to?

  • Quote

Post by macawgumbo » Tue Mar 13, 2007 5:58 pm

what exactly would /^(?:(d+)|::)* equate to if you say would including it in a grep statement?
**The man with one ball uses Linux, the man with both uses Gentoo. Who do you think performs better?**
Top
Hu
Administrator
Administrator
Posts: 24398
Joined: Tue Mar 06, 2007 5:38 am

Re: Perl: /^(?:(d+)|::)* what does that equate to?

  • Quote

Post by Hu » Wed Mar 14, 2007 2:03 am

macawgumbo wrote:what exactly would /^(?:(d+)|::)* equate to if you say would including it in a grep statement?
That expression expands as:

^: Match at beginning
*: zero or more of these
(?:()): groups like bare parentheses, but does not affect backreferences
d+: one or more lowercase d
|: alternative
::: a pair of colons

This should be parsed as: a sequence of d interspersed with pairs of colons, zero or more times. I think the equivalent grep would be: grep -E '^((d+)|::)*'.
Top
frostschutz
Advocate
Advocate
User avatar
Posts: 2978
Joined: Tue Feb 22, 2005 11:23 am
Location: Germany

  • Quote

Post by frostschutz » Wed Mar 14, 2007 2:16 am

...and this grep is pretty much pointless (unless you're using color grep or something), as it returns every line. Every line has a beginning of the line, and it contains ((d+)|::) at least zero times. :-)
Top
Hu
Administrator
Administrator
Posts: 24398
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Wed Mar 14, 2007 4:16 am

frostschutz wrote:...and this grep is pretty much pointless (unless you're using color grep or something), as it returns every line. Every line has a beginning of the line, and it contains ((d+)|::) at least zero times. :-)
Sure, but he didn't say it had to be useful. :) Besides, since he left off the trailing slash for his perl pattern, he might have some other expression that he is appending to this.
Top
nutbar
n00b
n00b
Posts: 5
Joined: Wed Jul 06, 2005 3:10 pm

  • Quote

Post by nutbar » Wed Mar 14, 2007 4:57 am

^(?:(d+)|::)*

If you're still having a bit of trouble reading this, I find it easier to read it from the inside out by sectioning things off separated by the () brackets. What it translates to is close to what Hu said, but not exactly.

Matching from the beginning of the line, find one or more "d"'s or a set of colons "::" zero or more times.

The ^ matches the beginning of a line.
The () brackets are submatches (just think of it as a way to separate one set of match settings from another).
The (?:...) sequence means a submatch but the ?: part tells it to NOT store this submatch as a backreference (unused in this query) - useful since you're only allowed 9 submatches usually (what ever the amount may be, it's finite).
The (...|...) sequence is a submatch where the pipe is just like saying OR between the various matches it separates.
The + quantifier means one or more occurances
The * quantifier means zero or more occurances

If you want to begin to really understand regular expressions, I suggest you start with basic RE's by reading the regex man page (which also covers extended RE's as well). Once you have a firm grasp on POSIX RE's, you can understand Perl RE's much easier.
Top
wynn
Advocate
Advocate
User avatar
Posts: 2421
Joined: Fri Apr 01, 2005 10:45 am
Location: UK

  • Quote

Post by wynn » Wed Mar 14, 2007 9:09 am

nutbar wrote:If you want to begin to really understand regular expressions, I suggest you start with basic RE's by reading the regex man page (which also covers extended RE's as well). Once you have a firm grasp on POSIX RE's, you can understand Perl RE's much easier.
"Mastering Regular Expressions: Powerful Techniques for Perl and Other Tools" by Jeffrey E. F. Friedl is very good too.
The avatar is jorma, a "duck" from "Elephants Dream": the film and all the production materials have been made available under a Creative Commons Attribution 2.5 License, see orange.blender.org for details.
Top
macawgumbo
Apprentice
Apprentice
Posts: 165
Joined: Fri May 28, 2004 1:12 am

  • Quote

Post by macawgumbo » Wed Mar 14, 2007 2:29 pm

Yes, this statement is absolutely pointless, but somebody thought I should spend time figuring it out. You can see how productive we are here in the office throwing these types of expressions around to solve. Thanks for the recommendations on where to look for reference as I am sure I will be reading up on it in the near future.
**The man with one ball uses Linux, the man with both uses Gentoo. Who do you think performs better?**
Top
wynn
Advocate
Advocate
User avatar
Posts: 2421
Joined: Fri Apr 01, 2005 10:45 am
Location: UK

  • Quote

Post by wynn » Wed Mar 14, 2007 4:39 pm

...and when you're tired of life, you can always try to fathom "perl one-liners" like those in http://www.consultix-inc.com/consultix/ ... rlcmds.pdf
The avatar is jorma, a "duck" from "Elephants Dream": the film and all the production materials have been made available under a Creative Commons Attribution 2.5 License, see orange.blender.org for details.
Top
Post Reply

8 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic