codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  perl \ query  aiyer100 at 03:48 on Monday, March 16, 2009
 

I intend to write a perl code that goes someting like this:
$mytest1 = "\abc";
$myrep1 = "@\abc";
$mystring =~ s/$mytest1/$myrep1/g;

In other words, I need this to replace every occurence of \abc with @\abc.
I tried using $mytest1 = "\\abc";
but that does not seem to work..in fact it replaces even instances of "abc" with "@abc".
Any suggestions on how to do this one?
thx
Anand

  Re: perl \ query  hermanningjaldsson at 09:28 on Monday, March 16, 2009
 

to replace every occurence of \abc with @\abc.

i think the following should work:
$mystring =~ s/\\abc/\@\\abc/gi;



  Re: perl \ query  S_Flex at 10:56 on Monday, March 16, 2009
 

lots of ppl have problems with perl regex but once you learn the basics it becomes fun to use and can save lots of time.

my example has only been tested with the test sting below, it should be able to handle all cases.

my $mystring = '555\abc\abcTTT\abc4421';
my $mytest1 = '\abc'; # Note (1) The way I quoted
my $myrep1 = '@\abc';

$mystring =~ s/\Q$mytest1\E/$myrep1/g; # Note 2 \Q and \E
print $mystring;

Note (1): The quote used for the 2 test/replace strings will disable any types of regex and display the text as it is.

Note (2): \Q is for "quote (disable) pattern metacharacters till \E" and \E "end case modification".

Reference Guide:
http://perldoc.perl.org/perlre.html#Regular-Expressions
http://perldoc.perl.org/perlreref.html








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  How do I pass javascript cart variables to asp email body?
•  How do I pass javascript cart variables to asp email body?
•  Converting 8 byte hex value to datetime value
•  NEWBIE in need of help.
•  Re: perl \ query
•  Re: how to create forum using asp.net with c# language?
•  can I replace????????????
•  Re: scrolling effect needed
•  Reading emails from outlook and storing in Database


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009