LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-28-2008, 09:31 AM   #1
hottdogg
Member
 
Registered: Aug 2004
Distribution: opensuse ,debian/ubuntu
Posts: 222

Rep: Reputation: 30
regex noob question : a(b|c) and a[bc] same ?


what's the difference between these patterns:
a(b|c) and a[bc] ?

I supposed there's no difference but plz CMIIW..
Tnx.
 
Old 03-28-2008, 09:37 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
There are multiple implementations of regular expressions. There can be be subtle differences. For example, in perl REs, the former will make available the portion in parenthesis in the $1 variable, and the second won't.

Which sort of RE are you talking about?
 
Old 03-28-2008, 10:04 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
In this case there is no difference, but that's just a coincidence. The first allows you to have multiple-character alternatives whereas the second doesn't, but allows you to exclude individual characters. For example:
Code:
a[bc] == a(b|c) == (ab|ac)
ab[cde] == ab(c|d|e) == a(bc|bd|be)
a[^bc] == (doesn't convert)
(doesn't convert) == (ab|cd)
ta0kira

Last edited by ta0kira; 03-28-2008 at 12:42 PM.
 
  


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
awk regex question Guest1234 Programming 6 12-25-2007 01:31 PM
sed regex question ShaqDiesel Programming 1 02-09-2007 07:24 PM
Regex question once again Isotonik Linux - Newbie 2 06-14-2006 02:15 PM
regex question Toadman Linux - General 0 12-30-2005 12:59 PM
perl regex question JustinHoMi Programming 5 03-20-2002 07:46 AM

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

All times are GMT -5. The time now is 10:42 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