允许HTML 4.01 ID值的正则表达式 [英] Allowed HTML 4.01 id values regex

查看:711
本文介绍了允许HTML 4.01 ID值的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以帮我建立相匹配的有效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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆