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 06:34 PM
Complex Pipeline/Redirection/Regular Expression problem netmaster UNIX for Dummies Questions & Answers 1 11-28-2005 09:55 PM
Regular Expression + Aritmetical Expression Z0mby Shell Programming and Scripting 2 05-21-2002 07:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-21-2006
Registered User
 

Join Date: Feb 2006
Posts: 27
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  
Old 06-21-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
Wrong input, deleted........

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

Join Date: Feb 2006
Posts: 27
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  
Old 06-21-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
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  
Old 06-21-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
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  
Old 06-21-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,693
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 Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:28 PM.


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

Content Relevant URLs by vBSEO 3.2.0