Re: regular expresion problem



Hi,

That is because the * is greedy. It will expand the match as far as it
can. Place a question mark after the * to make it lazy.

$prefec_test = "/(.*?[\+_]).*/";

MD wrote:
I am trying to figure out the regular expression problem
In case of $test1, I want to have @@@_ as a result
and for $test2 @@@+. How can i achieve this?
When testing $test1 variable always gives me @@@_@@_A
as a output string. I don't know why this happen either.

//$test1 = "@@@_@@_AAA";
$test2 = "@@@+@@+AAA";

$prefec_test = "/(.*[\+_]).*/";
if(preg_match_all($prefec_test, $test, $item)){
foreach($item[1] as $link)
{
echo $link;
}
}

Thanks in advance.

MD.

.



Relevant Pages

  • Re: simple regular expression problem
    ... regular expressions are "greedy" and will grab as much ... grabbing everything between the first opening tag and the last closing ... The question mark says, don't be greedy, and you get the ...
    (comp.lang.python)
  • Re: The Bush Tax Cuts
    ... the only place they can "horde" it makes it available for loans. ... Greedy people expand their businesses so they can make more money. ... People who expand their businesses generally have to hire more people. ...
    (rec.sport.football.college)
  • Re: Some part of the text should not be converted
    ... choose to do it together with the substitution, ... Note the question mark in ".+?". ... In reference to your question, yes, ... or the match will be greedy. ...
    (perl.beginners)
  • Re: simple regular expression problem
    ... regular expressions are "greedy" and will grab as much ... grabbing everything between the first opening tag and the last closing ... The question mark says, don't be greedy, and you get the ...
    (comp.lang.python)