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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pattern match an area code (510)

Status
Not open for further replies.

calabama

Programmer
Feb 19, 2001
180
US
I have managed to patern match / substitute every thing in a doc I am working on but cannot understand how to pattern match-subsitute "(510)" for ""

s/(510)//g;


Thanks for any help

TIm Briggs
 
I hate when that happens.
I have searched for hours for the answer.
Finally after posting I find it.
----------------------------------------------------------
These are the characters that are given special meaning within a regular expression, which you will need to backslash if you want to use literally:. * ? + [ ] ( ) { } ^ $ | \ Any other characters automatically assume their literal meanings.

You can also turn off the special meanings using the escape sequence \Q . After perl sees \Q , the 14 special characters above will automatically assume their ordinary, literal meanings. This remains the case until perl sees either \E or the end of the pattern.

For instance, if we wanted to adapt our matchtest program just to look for literal strings, instead of regular expressions, we could change it to look like this:

if (/\Q$pattern\E/) {

Now the meaning of + is turned off:



 
Hi Calabama,

I didn't know about the \Q thing -- thanks.

You can also turn off the special meaning just for the one character, like this.

/\(510\)/;

That pattern will match the string '(510)'.
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top