in reply to unable to fomulate right regular expression to fetch the intermediate and last word from a line (windows path) using delimiter "\"

I think we are all getting confused.

Do you perhaps mean to get the path-component, just after the --what you call-- key? It just happens to be the last and next-to-last component in your examples, but that is just sheer co-incidence.

The following code will extract the next path-element after the key:

use strict; use warnings; use 5.012; my $key= quotemeta 'C:\abc\dfg'; # we must escape all meta-characters while (<DATA>) { chomp; if (/$key\\([^\\]+)/) { say "$_ : $1"; } else { say "$_ : no match"; } } __DATA__ C:\abc\dfg\axy C:\abc\dfg\#@$#@$@\hwllo C:\abc\dfg
Output:
C:\abc\dfg\axy : axy C:\abc\dfg\#@$#@$@\hwllo : #@$#@$@ C:\abc\dfg : no match

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

  • Comment on Re: unable to fomulate right regular expression to fetch the intermediate and last word from a line (windows path) using delimiter "\"
  • Select or Download Code