Regular "regular" Perl regular full match words how to write (Forward-looking)
This post was last edited by default7 on 2014-10-27 09:30:18
Using sublime or a lot of editing software search function will have this function, complete match words, how this is achieved?
/**
* @param $str
*
* @return String
*/
function GetValue ($STR)
{
return Preg_match ('/(?: \ D) (\d{8}) (?: \ D)/', $STR, $matches)? $matches [1]: ";
}
$ARRSTR = [
' 10208899 ',//have
' #10208899 ',//have
' #test ^10208899 ',//have
' #ff1020889900 ',//None
' #0010208899 ',//None
' #1020 ^10208899a ',//have
' #5566880 &10208899f ',//have
' Test #10208899 ',//have
' #10208899. ' Yes
];
foreach ($arrStr as $i = = $str) {
$value = GetValue ($STR);
echo "$i \t{$str}\t\t=>\t{$value}\n";
}
The above match is wrong, 0, 1, 2, 7 these are not matched.
010208899=>
1#10208899=>
2#test^10208899=>
3#ff1020889900=>
4#0010208899=>
5#1020^10208899a=>10208899
6#5566880&10208899f=>10208899
7test? #10208899 =
8#10208899.=>10208899
------to solve the idea----------------------
function GetValue ($STR)
{
return Preg_match ('/(?: ^
------to solve the idea----------------------
\d) (\d{8}) (?: \ D
------to solve the idea----------------------
$)/', $STR, $matches)? $matches [1]: ";
}
010208899=>10208899
1#10208899=>10208899
2#test^10208899=>10208899
3#ff1020889900=>
4#0010208899=>
5#1020^10208899a=>10208899
6#5566880&10208899f=>10208899
7test. #10208899 =>10208899
8#10208899.=>10208899