need regular expression which could match a string like that "1B7FL26X3WS731388"
. Alphanumeric 17 character lenght.
I am using this expression.
$rEX = '/([A-Z0-9]){17}/';
but it also return a portion from a string like this "FGD798791B7FL26X3WS731388POPOD"
;
I need to select a string which is exactly 17 character long 18th character should not be Alphanumeric.
在样式中添加开始和结束:
$rEX = '/^([A-Z0-9]){17}$/D';
You should use ^ $ delimiters
$rEX = '/^([A-Z0-9]){17}$/';
To only allow uppercase alphanumeric 17 length string
You regular expression will allow all strings that contains a SUBSTRING of uppercased alphanumeric 17 lenght string.
$rEX = '/[^A-Z0-9]([A-Z0-9]){17}[^A-Z0-9]/';
should do. [^...]
negates the character class.
$rEX = '/[^A-Z0-9]+([A-Z0-9]){17}[^A-Z0-9]+/';
这会做
^([a-zA-Z0-9]){17}([^a-zA-Z0-9])*$
try this....
<?php
$title='1B7FL26X3WS731388';
$result = preg_replace("/[^a-zA-Z0-9]/", "", $title);
echo strlen($result);
?>
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.