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

delimiting special characters

Status
Not open for further replies.

zzzqqq

Programmer
Oct 12, 2005
17
IE
Hi,
Anyone know of a complete function that would delimit majority of special characters in a string?
E.g. +,-,@,space, /
Know I can use the translation function for tr/replace/original/d for individual characters, could this be used for groups of characters? Space and + are the major characters I am concerned about.
Cheers,
Mark.
 
$string=~s/[group]/replacement/g;


Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Can you explain exactly what you mean by "delimit"?
 
Cheers,
Thanks for the replies. Have problems with txt files.
reading file line like this:

Visual C++
Error message: Nested quantifiers in regex: <-- Here in m/"InstallShield for Microsoft Visual C++ <-- HERE 6"/
Is there a problem with ++ quantifier?

I already understood the s/[replacement characters]/characters replaced by/g
Just wondering how this would work for number of replacement characters:
s/['"/\]/'"/\/g
Can this be used to replace individual characters with individual characters. i.e. ' with \' or something?
Cheers,
Mark.

 
Hi,
actually have found solution to what I was interested in doing:
E.g. $microsoftProductNumber = grep /\Q$microsoftProductName/,@microsoftProducts;

Use \Q and this turns off special character meaning for strings when comparing to the regex.
Thanks to everyone who helped in this case.
Cheers,
Mark.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top