in reply to Re^2: To Match the text
in thread To Match the text

Hi. Please put your code fragments between <code>...</code> tags. Then, your RE becomes $var=~s#\b(\d(?:[a-z]{1})?\-?\d(?:[a-z]{1})?)\b#'<t>'.$1.'</t>'#ges;. Note that the [..] becomes a link when used outside code sections.

From what you describe, I guess you want to do a match only, but your code fragment tells something different (substitution). I guess you want to match the text after the first comma (maybe without the surrounding whitespaces?), so you could try

#... # alt1: match only, leave $var unmodified: my $var = "sclerosing 1954, 5–7, 54, 59f-60d, 90, 114"; if ( $var =~ /^[^,]+,\s*(.+?)\s*$/ ) { print "Match: ==>$1<==\n"; # ==>5–7, 54, 59f-60d, 90, 114<== } # alt2: add <t>markup</t>, substitute $var2: my $var2 = "sclerosing 1954, 5–7, 54, 59f-60d, 90, 114"; if ( $var2 =~ s{^([^,]+,\s*)(.+?)(\s*)$}{$1<t>$2</t>$3} ) { print "Markup: ==>$var2<==\n"; # ==>sclerosing 1954, <t>5–7, 54, 59f-60d, 90, 114</t><== } #...
Hi i tried the below but it's cating the number 1954.
Here, your code fragment returns: 5–7, <t>54</t>, <t>59f</t>-<t>60d</t>, <t>90</t>, 114 ???

It is hard to guess what you really want, so if the explanation above doesn't help, please explain your problem more clearly. E.g. by providing examples of what your input is and what output you expect (a few lines each within <code>..</code> tags).

BTW: You don't need the e-modifier. Instead of s{(pattern)}{'<t>'.$1.'</t>'}e a simple s{(pattern)}{<t>$1</t>} would be sufficient.

Replies are listed 'Best First'.
Re^4: To Match the text
by Anonymous Monk on Mar 22, 2009 at 17:12 UTC
    Hi Perlbotics and all,
    Basically iam doing Index for the book.
    my Sample text is:

    sclerosing 1954, 5–7, 54, 59f-60d, 90, 114
    cribriform carcinoma, invasive, 89, 91–94, 112
    comedo-type DCIS, 25–26
    comedo-type necrosis, LCIS with, 55, 59, 65
    complex sclerosing lesions (radial scar), 8–9, 54, 59, 90

    In this i want to match the numbers only. In the string there will be so many comma's, so it's not possible to match the first comma's. Is there any way to match the numbers given in the above sample.
    waiting for your reply.
    Regards,
    Mythili B