Hey all,
I have a txt document I'm trying to reformat so that it can be used in print. I read somewhere that I can UTF-8 by specifying it at the beginning of the document
use utf8; and can refer to it in regular expression substitutions or translations as in this example:
$s =~ s/-/\x{2014}/g;. This should turn a hyphen into an em dash correct?
My larger problem is that I have a string on which I would like to do a global substitution. The problem is, I only want to do the substitutions on the hyphens which are surrounded by 3 digits on both sides. There's a lot of other hyphens in the string and I don't want to have to go through and make a whole bunch of substrings or split the string into an array at those particular hyphens. Is there a way to match a regex but to only substitute the hyphen in it?
Here's and example of non-working code:
my $str = "725-275 is an entry - and will be at 423-569 -but- not at 0
+12-457.";
$str =~ s/\d{3}-\d{3}/\d{3}\x{2014}\d{3}/g;
(Yes, I am aware that the result would be grammatically incorrect.)
Unfortunately, this throws an error: "Unrecognized escape \d passed through"
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.