<?php
$texto = <<<TEXT0
teste:12>45
TEXT0;
$pattern = '([a-zA-Z0-9_]+)\:([0-9]+)\>([0-9]+)';
ereg( $pattern, $texto, &$match);
array_shift( $match );
print_r($match);
?>
O Resultado:
Array
(
[0] => teste
[1] => 12
[2] => 45
)
Olá grupo!Atualmente, tenho a seguinte expressão regular:([a-zA-Z0-9_]+)(\:([0-9]+)(\>([0-9]+)+)+)?Ao testar com um valor " teste:12>45 ", por exemplo, ele me retorna o seguinte:Match 1: testeMatch 2: :12>45Match 3: 12Match 4: >45Match 5: 45Pois bem. Gostaria de saber como eu poderia retornar apenas 3 match's (no caso acima, eu gostaria apenas do 1, 3 e 5 (valores 'teste', '12' e '45')).Alguma idéia?
<?php
// 'teste', retornará apenas [0] = teste
$pattern = '/(([a-zA-Z0-9_]+)([:]([0-9])+(\>([0-9]+))?)?)/';
preg_match( $pattern, "teste", &$match);
printf(" 'teste' ");
print_r($match);
// 'teste:12', retornará [0] = teste, [1] = 12
$pattern = '/(([a-zA-Z0-9_]+)([:]([0-9]+)(\>([0-9]+))?)?)/';
preg_match( $pattern, "teste:12", &$match);
printf(" 'teste:12' ");
print_r($match);
// 'teste:12>14', retornará [0] = teste, [1] = 12, [2] = 14
$pattern = '/(([a-zA-Z0-9_]+)([:]([0-9]+)(\>([0-9]+))?)?)/';
preg_match( $pattern, "teste:12>14", &$match);
printf(" 'teste:12>14' ");
print_r($match);
// 'teste>14', retornará apenas [0] = teste
$pattern = '/(([a-zA-Z0-9_]+)([:]([0-9]+)(\>([0-9]+))?)?)/';
preg_match( $pattern, "teste>14", &$match);
printf(" 'teste>14' ");
print_r($match);
?>
O Resultado:
'teste' Array
(
[0] => teste
[1] => teste
[2] => teste
)
'teste:12' Array
(
[0] => teste:12
[1] => teste:12
[2] => teste
[3] => :12
[4] => 12
)
'teste:12>14' Array
(
[0] => teste:12>14
[1] => teste:12>14
[2] => teste
[3] => :12>14
[4] => 12
[5] => >14
[6] => 14
)
'teste>14' Array
(
[0] => teste
[1] => teste
[2] => teste
)
RsrsrsrsBom, a única maneira que consegui até agora foi essa:([a-zA-Z0-9_]+)(\:([0-9]+)(\>?([0-9]+)+)?+)?Nele, pelo o que testei, satisfaz todas as condições.O único problema é que ele retorna 5 resultados, e não 3 como eu gostaria.Mas, se não tem como melhorar, está ótimo então :)Agradeço a ti e ao Felipe que ajudaram ;)
----- Original Message -----From: Felipe PenaSent: Wednesday, September 16, 2009 3:11 PMSubject: [Grupo-Regex] Re: Pegar valores entre caracteres