The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regex question xiamin Shell Programming and Scripting 3 03-05-2009 02:53 AM
RegEx question has me stumped tolmark UNIX for Dummies Questions & Answers 7 08-18-2007 06:20 PM
regex question arushunter Shell Programming and Scripting 8 01-04-2007 05:49 PM
regex question about greediness fedora Shell Programming and Scripting 3 08-30-2006 08:13 PM
regex question rocketkids UNIX for Dummies Questions & Answers 6 02-12-2004 05:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-06-2007
retrovertigo retrovertigo is offline
Registered User
  
 

Join Date: Jun 2007
Posts: 6
Quick regex question

Say that I want to match any of the following:

abc[123]
def[4567]
ghi[89]

The letters will either be "abc", "def", or "ghi", only those three patterns. The numbers will vary, but there will only be numbers between the brackets.

I've only been able to match abc[123], using the following:

Code:
abc.[0-9]*.
I'm using a wildcard in place of the brackets because you apparently cannot match brackets with a regex (or so I've read while trying to research how to do this). However, this is odd... I would think that:
Code:
abc.[0-9]+.
should work because there has to be at LEAST one digit. However, it's not working. I can only get it to work using:
Code:
abc.[0-9]*.
I'm wondering if the fact that I'm executing this script on a mac has anything to do with it.

Does anyone know a way that I can match the above?

P.S. this is in the bash shell

Last edited by retrovertigo; 07-06-2007 at 04:45 PM..
  #2 (permalink)  
Old 07-06-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
I think that the program you are using to match regexp doesn't support extended regexp, for example:

Code:
echo "abc[123]" | grep "abc.[0-9]+."
this won't return anything, while this:

Code:
echo "abc[123]" | egrep "abc.[0-9]+."
will return the matching string.

Matching a square bracket will require an escape character "\":

Code:
echo "ghi[9876543]" | egrep "(abc|def|ghi)\[[0-9]+\]"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:52 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0