I was reading the post for
Regular Expression Help and it occurred to me that a zero-width positive lookbehind would solve the problem neatly. As it turns out, there are a couple of problems with that solution. The first is that the lookbehind only finds fixed length expressions. If you're not sure of how long the text to match prior to your target text, you're out of luck.
Let's, however, assume for the sake of argument that the problem in Regular Expression Help was the following: need to match the beginning of the string, followed by five all caps and a colon and then we need to substitute out the colon. The following is the closest I could do it:
#!/usr/bin/perl -w
use strict;
my $test = "ASDFE:asdfe";
$test =~ s! # Substitute
(?<= # Zero-width positive lookbehind
[A-Z]{5} # Five caps
) # end lookbehind
: # Substituting a colon (but not the preceeding
+ characters)
!:</B>\n<BR><BR>!x;
print $test;
The problem is that I am not matching the five caps to the beginning of the string. Is this impossible with a lookbehind?
Cheers,
Ovid
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.