开发者

preg_match make sure first character in string is uppercase or lowercase letter

开发者 https://www.devze.com 2023-02-13 06:59 出处:网络
can someone show me the regex for this preg_match. I want to make sure first letter in string is nothing but a letter, either uppercase or lowercase. thanks. I found this, but it doesnt seem to be wor

can someone show me the regex for this preg_match. I want to make sure first letter in string is nothing but a letter, either uppercase or lowercase. thanks. I found this, but it doesnt seem to be working.

var_dump(preg_match("^/[A-Za-z]+/", $search_terms ));

The line above returns false, ever开发者_开发问答y time.


"^/[A-Za-z]+/" should be "/^[A-Za-z]+/"


What about something like this, for your regex :

/^[A-Za-z]/
  • Begins with : ^
  • One character that is a letter : [A-Za-z]

The ^ symbol should be at the beginning of the regex, but inside its delimiters ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消