Hi Perl monks,
I have a problem involving the split function applied to a text containing many different Unicode variations of A, B, C...Z. I want to get the list of words of any text I feed it, including the ones that have "®" or "™" attached to a word. Unfortunately, the regex I got so far also attaches "…" or "†" (dagger) to the words, so that I get "Canal†", "old..." and “ kraal¹ “ instead of simply "Canal", "old" and “kraal”.
Here's the script:
#!/usr/bin/perl
usewarnings;
$textBlock="Belgium is a monarchy. Ionuț, close the door. The bui
+ldings in Japan.
This is a sky-blue* \"material\". Here's the list:
The Eire Canal† is old…
Is Apple™ only a computer company?
www.fjydhjfjxerhuir.com is the site — go there. old-man-of-the-woods
(forget-me-not) [digital] bogus_address99@geemail.com
She's there. replace «date»
They live in a kraal¹. façade
Mac OS X® is slated to ship in May. Überzone șăâțî
http://language.perl.com/faq";
@wordList=split/[^-A-Z®À-ÖØ-öù-žǍ-ȚḀ-ẛẠ-&#
+7929;™]+/i, $textBlock;
foreach (@wordList) {
print "$_\n";
}
As you can see, I try to determine the delimiters needed for the split to be anything else except the characters included in this interval --> "-A-Z®À-ÖØ-öù-žǍ-ȚḀ-ẛẠ-ỹ™", but I still get unwanted punctuation characters added to words... There's no overlaping between these characters (i.e., they are in the proper order, with "-" first at 0045 and "™" (the trademark symbol) last at 8482, if i remember correctly :^)
So... what am I doing wrong? Please enlighten me...
(I have Perl 5.8.8 on Mac OS X, if that matters)
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.