[thelist] Perl Regex

martin.p.burns at uk.pwcglobal.com martin.p.burns at uk.pwcglobal.com
Wed Apr 4 04:46:36 CDT 2001


Memo from Martin P Burns of PricewaterhouseCoopers

-------------------- Start of message text --------------------

Another couple of Perl niceities are $` and $' which give you the content
on the line before and after (respectively) the pattern the regexp finds.
In this case:

$string = "<TITLE>Test title</TITLE>";
$string =~ s/<[^>]+>//g;
print "$string\n";
print "$`\n";
print "$'\n";

will give the result:

Test title
<TITLE>
</TITLE>

Cheers
Martin





Please respond to thelist at lists.evolt.org

Sent by:  thelist-admin at lists.evolt.org

To:   thelist at lists.evolt.org
cc:


Subject:  Re: [thelist] Perl Regex


On 4/4/01 at 9:29 AM, Manish Sharma <msharma at satyam.net.in> wrote:

> What's the best Perl Regex that matches HTML tags in a line?


$string = "<TITLE>Test title</TITLE>";
$string =~ s/<[^>]+>//g;
print "$string";

Result:
   "Test title"

The expression matches all occurrences of a "<", followed by one or more
characters that aren't a ">", followed by a ">". If you don't have the "g"
at the end, it will only match the first occurrence.



--------------------- End of message text --------------------

The principal place of business of PricewaterhouseCoopers and its associate
partnerships is 1 Embankment Place, London WC2N 6NN where lists of the
partners' names are available for inspection. All partners in the associate
partnerships are authorised to conduct business as agents of, and all
contracts for services to clients are with, PricewaterhouseCoopers. The UK
firm of PricewaterhouseCoopers is authorised by the Institute of Chartered
Accountants in England and Wales to carry on investment business.
PricewaterhouseCoopers is a member of the world-wide
PricewaterhouseCoopers organisation.
----------------------------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material.  Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited.   If you received
this in error, please contact the sender and delete the material from any
computer.





More information about the thelist mailing list