简体   繁体   中英

PHP Match the string to regex, if after the matched string are no digits

Lets say that I have a excel function like that IF(A1>0,1,2) I match it by pregex and by dictionary I translate it into Czech language ( KDYŽ(A1>0,1,2) ). When I would translate it back I should get the same string, but instead of it I get IF(AND1>0,1,2) . Because "A" is in Czech "AND" which is one of key words in excel function.

So I need to grep all letters while after them is no number (= not cell name), how to achieve that while I'm using this code to get array of matched words?

$text = strtolower("KDYŽ(A1>0,1,2)");

if (preg_match_all('/[a-zěščřžýáíéúůóďťň]+/i',$text,$match)) {
  /* matched text should be:
  $match[0] = "KDYŽ";
  no $match[1] = "A" should exists;*/
}

Use

'/[a-zěščřžýáíéúůóďťň]+[^0-9]/i'

which maches your characters not followed by a 0-9. You'd need to strip the last character from your match though since the first character following the string you search will be returned, too.

Or, try

'/[a-zěščřžýáíéúůóďťň]+(?![0-9])/i'

which is a negative look-ahead.

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