CSS类选择器中允许使用哪些字符或符号?
我知道以下字符是无效的,但是哪些字符是有效的?
~ ! @ $ % ^ & * ( ) + = , . / ' ; : " ? > < [ ] \ { } | ` #
CSS类选择器中允许使用哪些字符或符号?
我知道以下字符是无效的,但是哪些字符是有效的?
~ ! @ $ % ^ & * ( ) + = , . / ' ; : " ? > < [ ] \ { } | ` #
[^a-z0-9A-Z_-]
这是一个反向匹配,选择任何不是字母、数字、破折号或下划线的内容以便于删除。
^-*[0-9]+
这个正则表达式匹配字符串开头的0或1个破折号,后面跟着1个或多个数字,方便删除。
在PHP中的使用方法:
// Make alphanumeric with dashes and underscores (removes all other characters)
$class = preg_replace("/[^a-z0-9A-Z_-]/", "", $class);
// Classes only begin with an underscore or letter
$class = preg_replace("/^-*[0-9]+/", "", $class);
// Make sure the string is two or more characters long
return 2 <= strlen($class) ? $class : '';
.hello/world
类:.hello\2fworld
,hello\2f world
或hello\/world
。 - wyqydsyq