Connecting Tech Pros Worldwide Forums | Help | Site Map

Reg. Regular Expression...

Member
 
Join Date: Dec 2007
Posts: 40
#1: Oct 10 '09
Hi All,

what's wrong in this code...

Reguired Output: \\DirPath\Dir1\Dir2\File2.ext

Expand|Select|Wrap|Line Numbers
  1.  
  2. $FilePath='
  3. \\DirPath\Dir1\Dir2\File1.ext
  4. \\DirPath\Dir1\Dir2\File2.ext
  5. \\DirPath\Dir1\Dir2\File3.ext
  6. ';
  7.  
  8. if($FilePath=~m#\\\\DirPath\\Dir1\\Dir2\\File2.ext#)
  9. {
  10. print "File Path: $&\n";
  11. }
  12. else
  13. {
  14. print "Path Not Found";
  15. }
  16.  
  17.  
I do know whats wrong in this code. I didn't get the expected output.

Looking for ur suggestions.

Thanks,
Sabarish.

Newbie
 
Join Date: Sep 2009
Posts: 15
#2: Oct 10 '09

re: Reg. Regular Expression...


This works for me:

Expand|Select|Wrap|Line Numbers
  1. if($FilePath=~m#\\DirPath\\Dir1\\Dir2\\File2.ext#)
The 4 leading backslashes are too many; 2 works.
Reply