允许HTML 4.01 ID值的正则表达式 [英] Allowed HTML 4.01 id values regex
问题描述
您可以帮我建立相匹配的有效W3C HTML 4.01 ID
值一个正则表达式?
与W3C规范根据:
ID和名称标记必须以字母开头([A-ZA-Z]),并可能
。
其次是任意数量的字母,数字([0-9]),连字符( - ),
下划线(_),冒号(:)和句点(。)
块引用>解决方案您可以使用此正则表达式
^ [A-ZA-Z] [\\ W:.-] * $
^
描述字符串的开头
[A-ZA-Z]
匹配一个大写的或小写字母
*
匹配preceding字符1到多次
\\ W
类似于[A-ZA-Z \\ D _]
$
是字符串的结尾Can you help me to build a regex that matches a valid W3C HTML 4.01
id
value?According with W3C specs:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
解决方案You can use this regex
^[a-zA-Z][\w:.-]*$
^
depicts the start of string
[a-zA-Z]
matches an uppercase or lowercase letter
*
matches the preceding character 1 to many times
\w
is similar to[a-zA-Z\d_]
$
is the end of string这篇关于允许HTML 4.01 ID值的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!