[Regular] Perl regular expressions completely match the regular expression of a word. how to write (forward) This post is last written by default7 from 2014-10-2709: 30: 18. how does one implement the Sublime or many editing software's search function to completely match words? ** & Nbsp; * & nbsp; @ param & nbsp; $ str & nbsp; [regular] how to write regular expressions that completely match words in Perl regular expressions (prospective)
This post was last edited by default7 at 09:30:18
How can I implement this function by using Sublime or the search function of many editing software to completely match words?
/**
* @ Param $ str
*
* @ Return string
*/
Function getValue ($ str)
{
Return preg_match ('/(? : \ D) (\ d {8 })(? : \ D)/', $ str, $ matches )? $ Matches [1]: '';
}
$ ArrStr = [
'20140901', // Yes
'#10208899', // Yes
'# Test ^ 10208899', // Has
'# Ff1020889900', // none
'#0010208899', // none
'#1020 ^ 10208899a', // Yes
'#5566880 & 10208899f', // Yes
'Test? #10208899 ', // Yes
'#10208899.' // Yes
];
Foreach ($ arrStr as $ I => $ str ){
$ Value = getValue ($ str );
Echo "$ I \ t {$ str} \ t => \ t {$ value} \ n ";
}
The above match is incorrect. 0, 1, 2, and 7 do not match.
010208899=>
1#10208899=>
2#test^10208899=>
3#ff1020889900=>
4#0010208899=>
5#1020^10208899a=>10208899
6#5566880&10208899f=>10208899
7test?#10208899=>
8#10208899.=>10208899
------ Solution ----------------------
Function getValue ($ str)
{
Return preg_match ('/(? : ^
------ Solution ----------------------
\ D) (\ d {8 })(? : \ D
------ Solution ----------------------
$)/', $ 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