Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regex question

Status
Not open for further replies.

dmazzini

Programmer
Jan 20, 2004
480
US
Regex Question

I have different valid Radio Frequency Modules Type:FRGA,FRIA,FREA,FRCA,FRDA,FRFA and FRGC

Code:
 if  ($module =~ /FR(G|I|E|C|D|F)A/)  # This regex covers FRGA,FRIA,FREA,FRCA,FRDA and FRFA
Now, I want to match module FRGC within regex, is it possible or I have to add "or" condition ?

Testing it
Code:
if  ($module =~ /FR(G|I|E|C|D|F)A|C/). # This regex works but it could give me non-valid RF module. e.g FRCC would pass.

Any advices?

dmazzini
GSM/UMTS System and Telecomm Consultant

 
Sorted guys

Code:
if  ($module =~ /FR(GA|IA|EA|CA|DA|FA|GC)/) 

[code]

Opps!

dmazzini
GSM/UMTS System and Telecomm Consultant
 
When you find yourself using the | operator for single-character options, you should be using a character class. If I were to do this with a regexp (though I'd personally prefer to use a hash of valid values, which makes it more extensible in future), I'd do:
Code:
 if  ($module =~ /FR[GIECDF]A|FRGC/)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top