Allowed HTML 4.01 id values regex

南笙酒味 提交于 2019-12-21 07:55:17

问题


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 (".").


回答1:


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



来源:https://stackoverflow.com/questions/14664860/allowed-html-4-01-id-values-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!