[英]Regular expression for alphanumeric characters
need regular expression which could match a string like that "1B7FL26X3WS731388"
. 需要正则表达式,它可以匹配类似于
"1B7FL26X3WS731388"
的字符串。 Alphanumeric 17 character lenght. 字母数字的17个字符长度。
I am using this expression. 我正在使用此表达式。
$rEX = '/([A-Z0-9]){17}/';
but it also return a portion from a string like this "FGD798791B7FL26X3WS731388POPOD"
; 但它也会从类似
"FGD798791B7FL26X3WS731388POPOD"
的字符串中返回一部分;
I need to select a string which is exactly 17 character long 18th character should not be Alphanumeric. 我需要选择一个长度恰好为17个字符的字符串,第18个字符不应为字母数字。
在样式中添加开始和结束:
$rEX = '/^([A-Z0-9]){17}$/D';
You should use ^ $ delimiters 您应该使用^ $定界符
$rEX = '/^([A-Z0-9]){17}$/'; $ rEX ='/ ^([A-Z0-9]){17} $ /';
To only allow uppercase alphanumeric 17 length string 只允许使用大写字母数字17长度的字符串
You regular expression will allow all strings that contains a SUBSTRING of uppercased alphanumeric 17 lenght string. 您的正则表达式将允许所有包含大写字母数字17长度SUBSTRING的字符串。
$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);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.