LinuxQuestions.org
Review your favorite Linux distribution.
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 12-19-2003, 12:22 PM   #1
Tramontane
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 39

Rep: Reputation: 15
regular expressions and back references within [] lists


It seems like a simple problem at first.

Let's start with an example:

using the data set
Code:
war
wee
wet
woo
I would like to be able to match the words war and wet while excluding wee and woo.

I can match wee and woo with this expression:
Code:
"^[a-z]([a-z])\1$"
Is there a way to use "back references" within [] lists?

The expression:
Code:
"^[a-z]([a-z])[\1]$"
does not produce the same results as the previous expression because instead of resolving the '\1' to an 'e' or 'o', it searches for the '\\' and '1' characters.

The reason this is a problem is that I thought that I would be able to write an expression like this:
Code:
"^[a-z]([a-z])[^\1]$"
So is there any way to resolve a back reference within [] lists?


I've been trying to think back to my CS classes to remember if it's even possible for REs to do this sort of thing.
 
Old 12-19-2003, 01:53 PM   #2
vladkrack
Member
 
Registered: Oct 2002
Location: Curitiba - Brazil
Distribution: Conectiva
Posts: 334

Rep: Reputation: 30
The usual reference is [^], but in this case will not work, so is easier to use an work around, like in egrep use the option -v to reverse the result of this expression...
 
  


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
Regular Expressions markjuggles Programming 2 05-05-2005 11:39 AM
Regular Expressions overbored Linux - Software 3 06-24-2004 02:34 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 10-31-2003 11:09 PM
Regular expressions aromes Linux - General 1 10-15-2003 12:29 PM
regular expressions? alaios Linux - General 2 06-11-2003 03:51 PM


All times are GMT -5. The time now is 11:20 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration