LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2019, 04:39 PM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
regex conditionals - conditional group contains more than two branches


I have the following content:
[QUOTE]----------
ID: php_install
Function: pkg.installed
Name: php
Result: True
Comment: All specified packages are already installed
Started: 16:19:04.217642
Duration: 587.977 ms
Changes:
----------
ID: mod_mysql
Function: pkg.installed
Name: php-mysql
Result: True
Comment: All specified packages are already installed
Started: 16:19:04.805807
Duration: 14.708 ms
Changes:
----------/QUOTE]

In this course I'm watching, I have the following example, which works as expected:
Code:
grep -Po '(ID|(?<fn>Function)|(?<dur>Duration)): (?(fn)\w+?\.\w+|(?(dur)\d+\.\d+ ms|\w+))' high20.txt
ID: php_install
Function: pkg.installed
Duration: 587.977 ms
ID: mod_mysql
Function: pkg.installed
Duration: 14.708 ms
But whenever I try this:
Code:
grep -Po '(ID|(?<fn>Function)|(?<comm>Comment)): (?(fn)\w+?\.\w+|(?(comm)\w+?\s\w+)|\w+))' high20.txt
I get the following error:
Code:
grep: conditional group contains more than two branches
Which really intrigues me, because the only significant difference I can see is the naming convention that I attribute to the regex ("comm" instead of "dur" and the regex itself which is only slightly difference, but I'd say there shouldn't make any difference to the syntax itself). Any ideas what's going on?

Never mind - an additional unnecessary paranthesis. Only after I posted it did I see it. I couldn't perceive it as such in the command line.
So instead of \s\w+)| it should have been \s\w+|

Last edited by vincix; 05-24-2019 at 04:46 PM.
 
Old 05-24-2019, 07:57 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Too many parentheses Indeed!

If that resolves the question please use the Thread Tools to mark this one solved.
 
  


Reply



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
Mirroring two branches using ftpsync horizn Debian 0 02-25-2017 03:44 PM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Help "merging" two mercurial (hg) "branches" sohmc Linux - Software 1 03-09-2011 12:58 AM
list all contains and subdirectories' contains babis Linux - Newbie 2 10-22-2004 09:40 PM
bash scripting - conditionals dguy Linux - Newbie 4 01-19-2002 08:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:07 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
Open Source Consulting | Domain Registration