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.
|