[Regular] Perl-style regular expressions completely match the regular expression of a word (prospective)

Source: Internet
Author: User
[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.