By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,934 Members | 1,685 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,934 IT Pros & Developers. It's quick & easy.

Reg. Regular Expression...

P: 40
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.
Oct 10 '09 #1
Share this Question
Share on Google+
1 Reply


Expert
P: 70
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.
Oct 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.