gpt4 book ai didi

css - CSS 标识符的允许字符

转载 作者:数据小太阳 更新时间:2023-10-29 09:15:53 31 4
gpt4 key购买 nike

CSS 标识符 idclass 的(完整)有效/允许 charset 字符是什么?

是否有可用于验证的正则表达式?它与浏览器无关吗?

最佳答案

字符集无关紧要。允许的字符更重要。检查CSS specification .这是相关的引用:

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as "B\&W\?" or "B\26 W\3F".

更新:关于正则表达式问题,你可以找到语法here :

ident      -?{nmstart}{nmchar}*

其中包含的部分:

nmstart    [_a-z]|{nonascii}|{escape}
nmchar [_a-z0-9-]|{nonascii}|{escape}
nonascii [\240-\377]
escape {unicode}|\\[^\r\n\f0-9a-f]
unicode \\{h}{1,6}(\r\n|[ \t\r\n\f])?
h [0-9a-f]

这可以转换为 Java 正则表达式,如下所示(我只在包含 OR 的部分添加了括号并转义了反斜杠):

String h = "[0-9a-f]";
String unicode = "\\\\{h}{1,6}(\\r\\n|[ \\t\\r\\n\\f])?".replace("{h}", h);
String escape = "({unicode}|\\\\[^\\r\\n\\f0-9a-f])".replace("{unicode}", unicode);
String nonascii = "[\\240-\\377]";
String nmchar = "([_a-z0-9-]|{nonascii}|{escape})".replace("{nonascii}", nonascii).replace("{escape}", escape);
String nmstart = "([_a-z]|{nonascii}|{escape})".replace("{nonascii}", nonascii).replace("{escape}", escape);
String ident = "-?{nmstart}{nmchar}*".replace("{nmstart}", nmstart).replace("{nmchar}", nmchar);

System.out.println(ident); // The full regex.

更新 2:哦,您更像是一个 PHP 爱好者,嗯,我认为您可以想出如何/在何处执行 str_replace

关于css - CSS 标识符的允许字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2812072/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com