[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: Regexp



In <JNIDPCDCKNFIIAAA@shared2-mail.whowhere.com>, "Dayen Wilmar" writes:
:I'm newbie in regular expression and perl.
:I had a problems, it's related with complex regular expression.

This is not the right place to ask for help: one good place to ask is
in the perl-related newsgroups, comp.lang.perl.*.

:Here is the following my small program:
:
:#!/usr/bin/perl
:$_   = '>jds kjdjk<sdsd>sdsd<sdsdsd> test wib ass <sfsf sf> q<sfsfqsf>q';
:$x   = m/\>.*?wib.*?</i;
:print "$&";
:
:The program will display:
:>jds kjdjk<sdsd>sdsd<sdsdsd> test wib ass <
:
:In the fact I want my program will display:
:> test wib ass <

The regexp engine will return the first match it finds, backtracking only
if it doesn't find a match. You can achieve what you ask for here using
a regexp such as /^.*(>.*?wib.*?<)/i (with the matched text in $1), or
/>[^>]*?wib.*?</i.

A careful reading of the 'Backtracking' section of the perlre manpage
might have allowed you to discern this, but I couldn't find specific
examples of this common source of confusion there nor in the FAQ with
a fairly quick check.

Hugo


References to:
"Dayen Wilmar" <dayen@gurlmail.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]