suniln:

On the line where you say:

$key="C:\abc\dfg";

Your string $key doesn't actually have any backslashes ('\') in it. When in double-quotes, the backslash is a special character that combines with the next character to tell perl what to insert into the string. For example, "\t" indicates a tab character (a byte containing 09H), and "\n" tells perl to start a new line (a byte containing 0DH). So the string: "dog\n\tcat" tells perl to build a string holding "dog", a newline, a tab character, and "cat". There are no backslashes in the string.

You can correct this problem by putting the value in single quotes, e.g.,

$key='C:\abc\dfg';

or you can tell perl you really want a backslash (by using two backslashes!):

$key="C:\\abc\\dfg";

Alternatively, you can use the forward slash: In most cases, Windows/DOS is happy with forward slashes in file names. Perl and Unix are happy with it too, so that's what I do nearly everywhere:

$key="C:/abc/dfg";

So, the long and short of it is that you're not matching because you have no backslashes in your string, along with any other problems the expression might have.

...roboticus

FYI: Be sure to preview your post and update the formatting before pressing the "create" button! Also, you can go back and update a post to add code tags, rather than start a new one.

Update: Fixed byte value for tab from "08H" to "09H". Thanks to bart for the catch!

Update: Fixed order of tab and newline in example text. Thanks to johngg for noticing that one.


In reply to Re^3: unable to fomulate right regular expression to fetch the intermediate and last word from a line (windows path) using delimiter "\" by roboticus
in thread unable to fomulate right regular expression to fetch the intermediate and last word from a line (windows path) using delimiter "\" by suniln

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.