Jump to content

Regexp - Why does not found match?


Bananslovak
 Share

Recommended Posts

Hello, I have an trouble - my question is about regular expressions.Source:

$text = "</u>()text()";$search = "@(</u>)([^//1]*?)$@is";preg_match($search,$text,$out);print_r($out);

Output:

Array ( [0] => ()text() [1] => [2] => ()text() )

It's good. But if I enter "/" after second "(" in $text variable, output is empty. Look:Source:

$text = "</u>()text(/)";$search = "@(</u>)([^//1]*?)$@is";preg_match($search,$text,$out);print_r($out);

Output:

Array ( )

If I enter after second "(" any character (besides "/"), it works. Does somebody tell me where is an error? Because I don't know where is it. Thanks very much to answers! Bananslovak

Link to comment
Share on other sites

I don't really see what are you trying to achieve, but... what's the

[^//1]

part? A negative lookahead for "//1"? If that was the intention, try to group it like

[^(//1)]

or try the other way of negative lookahead (which I think PCRE support) which is

(?!//1)

Link to comment
Share on other sites

You've got me an idea, problem is [^//1], it's interval of characters of first group, and I wand to negative full string, not only characters.My intention is get substring, witch is after last group of entered characters, in example above they are "</u>". Example I have string first<u>second</u>third<u>fourth</u>fifth, and I want to got fifth because this is after last "</u>".What to do this? Select all after last appearance of entered substring?Thanks

Link to comment
Share on other sites

This found substring after FIRST occurrence of </u>, but I want to found substring after LAST occurrence of </u>. In first<u>second</u>third<u>fourth</u>fifth your expression found third<u>fourth</u>fifth, because this is after FIRST "</u>". But I want found only fifth, I want found all of LAST, not FIRST occurrence of "</u>".Exist in regexp modifier, who set that expression found last match, not first match? This modifier exist in some PHP function who works with strings, but I forget her name. In regular expressions I don't found similar modifier.boen_robot thank you for struggle, but it don't help me.

Link to comment
Share on other sites

I don't know what you really mean with this. U modifier doesn't change anything.I thing this is probably hard work for only regular expressions. I try combined regexps and PHP functions strrpos and substr, and it work.Thanks for all, we can lock this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...