keep the ocurrence
Moderator: General Moderators
- visonardo
- Forum Contributor
- Posts: 136
- Joined: Mon Oct 02, 2006 7:49 pm
- Location: Argentina, South America´s Sun.
keep the ocurrence
i have this regex
(\"|')?(http|ftp)(s)?: ((\w+)\.)?(\w)+\.(com|net)(\.ar)?(\"|')?
the task is that must appear a url between ' or " but not with ' and " in the end, or viceversa. or if appear in the start exactly it must appear in the end. understand what i want? how is it?
(\"|')?(http|ftp)(s)?: ((\w+)\.)?(\w)+\.(com|net)(\.ar)?(\"|')?
the task is that must appear a url between ' or " but not with ' and " in the end, or viceversa. or if appear in the start exactly it must appear in the end. understand what i want? how is it?
Code: Select all
$string = "'dfd\"";
$pattern = '#("|\')(.*?)\1#';
preg_match($pattern,$string,$match);
var_export($match);
OUTPUT
array (
)
$string = "'dfd'";
preg_match($pattern,$string,$match);
var_export($match);
OUTPUT:
array (
0 => '\'dfd\'',
1 => '\'',
2 => 'dfd',
)- visonardo
- Forum Contributor
- Posts: 136
- Joined: Mon Oct 02, 2006 7:49 pm
- Location: Argentina, South America´s Sun.
Thank
but --> [^\1#]
and something like that? how is it? (i tested thus [^\1#] but didnt work)
idont understand how is to able almost anything but not a determinated word, here in some part someone asked that but was not so cleared the example that given like their reply. [^a] dont allow a letter, but i would like something thus [^(word1,word2,word3)] and it would not allow the words "word1", "word2" and "word3"
how it would be?
but --> [^\1#]
and something like that? how is it? (i tested thus [^\1#] but didnt work)
idont understand how is to able almost anything but not a determinated word, here in some part someone asked that but was not so cleared the example that given like their reply. [^a] dont allow a letter, but i would like something thus [^(word1,word2,word3)] and it would not allow the words "word1", "word2" and "word3"
how it would be?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
[] are a character class construct. The letters/numbers/what-have-you inside them are allowed to happen arbitrary to their order.
Matching entires words (or rather not matching words) involves a different construct called assertions.Is a (positive forward) assertion.is a negative (forward) assertion.
Matching entires words (or rather not matching words) involves a different construct called assertions.
Code: Select all
(?=word1|word2|word3)Code: Select all
(?!word1|word2|word3)- visonardo
- Forum Contributor
- Posts: 136
- Joined: Mon Oct 02, 2006 7:49 pm
- Location: Argentina, South America´s Sun.
thank you
but what happened here?
output
matchs null?

How i must use that?
but what happened here?
Code: Select all
<?
$b=' abc def ';
$fun2='(?=abc)';
preg_match_all("/".$fun2."/i",$b,$match);
print_r($match);
?>Code: Select all
Array
(
[0] => Array
(
[0] =>
)
)How i must use that?
- visonardo
- Forum Contributor
- Posts: 136
- Joined: Mon Oct 02, 2006 7:49 pm
- Location: Argentina, South America´s Sun.
other thing. This is my code:
when capture the first element the [0] is all it: ":function1('','http:www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif');"
(without double quotes in the beginning neither in the start, of course)
i print me:
if you see, it should capture :function1(...); and no more, but then of the ; it continue :s, why? if i said that ; is in the end. i tested puting [^;]* and not .* and it fix the problem, but i guess that i would not be needed, it should take until the first ; why happen that?
Code: Select all
<?
function ech($aver)
{
print_r($aver);
echo '<p>';
return;
}
$a=" something avascr:function1('','http:www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif'); <--- here was";
$fun="(?!javascript):[\w]+\([\S]*(('|\")((http|ftp)s?:(.*))\\2)[\S]*\);";
preg_replace_callback("/".$fun."/i","ech",$a);
?>when capture the first element the [0] is all it: ":function1('','http:www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif');"
(without double quotes in the beginning neither in the start, of course)
i print me:
Code: Select all
Array
(
[0] => :function1('','http:www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif');
[1] => 'http:www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif'
[2] => '
[3] => http:www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif
[4] => http
[5] => www.google.com/logo2.gif'); kjlskjfñal ñklasjfñlakj jlafñs here was ---> javascript:function2('','http:www.google.com/logo.gif
)
<p>if you see, it should capture :function1(...); and no more, but then of the ; it continue :s, why? if i said that ; is in the end. i tested puting [^;]* and not .* and it fix the problem, but i guess that i would not be needed, it should take until the first ; why happen that?
- visonardo
- Forum Contributor
- Posts: 136
- Joined: Mon Oct 02, 2006 7:49 pm
- Location: Argentina, South America´s Sun.
well, i changed (.*) by ([^;]*) in a part the problem has been fixed but the part (?!javascript) dont work because take too the functions that dont start with javascript and it should be not.
the last result (with the change that i told) is:
just would take one and not two, what is bad here?
the last result (with the change that i told) is:
Code: Select all
Array
(
[0] => :function1('','http:www.google.com/logo2.gif')
[1] => 'http:www.google.com/logo2.gif'
[2] => '
[3] => http:www.google.com/logo2.gif
[4] => http
[5] => www.google.com/logo2.gif
)
<p>Array
(
[0] => :function2('','http:www.google.com/logo.gif')
[1] => 'http:www.google.com/logo.gif'
[2] => '
[3] => http:www.google.com/logo.gif
[4] => http
[5] => www.google.com/logo.gif
)
<p>just would take one and not two, what is bad here?