The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expression Problem chris1234 UNIX for Dummies Questions & Answers 12 04-02-2008 04:44 AM
awk and regular expression maskot Shell Programming and Scripting 4 05-22-2007 04:22 AM
Regular Expression Problem netmaster UNIX for Dummies Questions & Answers 1 12-07-2005 05:34 PM
Complex Pipeline/Redirection/Regular Expression problem netmaster UNIX for Dummies Questions & Answers 1 11-28-2005 08:55 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 07:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-21-2006
Registered User
 

Join Date: Feb 2006
Posts: 27
Stumble this Post!
Regular Expression problem

Hi guys

I've been trying to write a regular expression.
If I'm tryin to validate a sequence of characters as follows...

AB1-232-623482-743 43/3

where

a) any character after the "AB" can be any alphanumeric character
b) the " 43/3" part is optional

is there a quick neat way for me to do this?

i know i could do something like

regexp=[A][b][A-Za-z0-9]-[A-Za-z0-9][A-Za-z0-9][A-Za-z0-9] etc etc

but this looks like a very untidy way to it..

Any help would br greatly appreciated.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-21-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 524
Stumble this Post!
Wrong input, deleted........

Last edited by tayyabq8; 06-21-2006 at 07:09 AM.
Reply With Quote
  #3 (permalink)  
Old 06-21-2006
Registered User
 

Join Date: Feb 2006
Posts: 27
Stumble this Post!
no. that won't work because the optional section needs to be validated to contain only a space followed by 2 alphanumeric characters, a forawrd slash and a further alphanumeric character.

All characters in the string must be validated therefore it is not possible to use *

thanks for trying though.
Reply With Quote
  #4 (permalink)  
Old 06-21-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 524
Stumble this Post!
Sorry for misunderstanding your requirements, I thought you were saying that AB1 and then any string, I'll work on your requirement and will come up with something neat.

Regards,
Tayyab
Reply With Quote
  #5 (permalink)  
Old 06-21-2006
tayyabq8's Avatar
UNIX Hobbyist
 

Join Date: Nov 2004
Location: /World/Asia/MiddleEast/Kuwait/Salmiya
Posts: 524
Stumble this Post!
How about this:
Code:
[AB].-...-......-... ../.
or if any string between AB1 and (space) you could also give this a try:
Code:
[AB].-.* ../.
OR
Code:
[A][b].* ../.
Take whatever suits your requirements.

Regards,
Tayyab

Last edited by tayyabq8; 06-21-2006 at 07:06 AM.
Reply With Quote
  #6 (permalink)  
Old 06-21-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,661
Stumble this Post!
Code:
sed -e "s_..[a-zA-Z0-9]-[a-zA-Z0-9]\{3\}-[a-zA-Z0-9]\{6\}-[a-zA-Z0-9]\{3\}_&_"
Its grep equivalent

Code:
grep -E "..[[:alnum:]]-[[:alnum:]]{3}-[[:alnum:]]{6}-[[:alnum:]]{3}"
grep -E "..\w-\w{3}-\w{6}-\w{3}"
\w is a synonym for [[:alnum:]]
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0