简体   繁体   中英

It finds characters only if there is an empty line at top and bottom

There's something really strange happening, and I'm hoping someone can figure this out for me please.

I'm using preg_match to find an exact character match in a file, yet for some reason or another, it's not finding it unless there's an empty line both at the top and at the bottom of the file.

Here is my code:

if ( @preg_match( "/([^0-9]{$uNumber}[^0-9])/", $numbers ) ) {

It will not find the search term if it is the only thing in the file. For instance, if the file is 12345 and you are searching for 12345 , then it won't find it. However if the file is x12345x then it will find it.

What you probably want to do is allow the start and end of the file to be allowed:

/(?:^|\D){$uNumber}(?:\D|$)/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM