Hello monks,
I got a small problem concerning references in perls regex flavor.
For example, I got a string like this
$lala = "Hello you therre."
And I want to match all double characters (a-z), i.e. ll and rr in the given string and contract them to one char. (Please do not take this seriously, its just an example.)
So I went like this:
$lala =~ s/([a-z])$1/$1/g
It does not work. So I played around:
$lala =~ s/([a-z])\1/$1/g
This works. But what I kept in mind was this:
Warning on \1 vs $1
So I don't know why in the first version the $1 in the matching part (not the substitute part) does not work but with \1 in the second version? I thought \1 is obsolete and just a relic of a sed styled referencing.
This is nothing big, but ... did I miss something?
Thanks in advance,
ocs.
tennis players have fuzzy balls.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.