This is probably the nastiest regex I ever had to use. It's goal was to highlight Extended Letter Sequences in text. The ELS had already been found, this routine went through and turned the letters of the hidden word into uppercase. This is just a 'capitalise every nth letter' challenge, and I cheated by stripping out the spaces first:
#Block is the chunk of text, word is the 'hidden' word and sep is the
+number of characters in the text between each word
my ($block, $sep, $word)=@_;
my @let = split //, $word;
my $rep;
my $i=1;
foreach my $l (@let) {$l = "(".$l.")(.{$sep})";$rep.=
+ '\u$'.$i++.'$'.$i++;};
my $regexp2 = join "", @let;
my $ev = '$block =~ '."s/$regexp2/$rep/i;";
# print "Now scanning block with $regexp2 and replacemen
+t target $rep\n";
return $block, $word if eval $ev;
The output looks like this:
---This is the original text----------------------------------------
m at times; this thread, like that of Ariadne, when once
unraveled will conduct one through a lab
---The ELS 'FNORD' is in capitals---------------------
mattimesthisthreadlikethatoFariadNewhenOnceunRaveleDwillconductonethro
+ughalab
BTW if there's an obviously better way to do this I'd be delighted to hear about it.
____________________
Jeremy
I didn't believe in evil until I dated it.
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.