RegEx不接受%

use*_*244 0 regex unicode character-properties

这套RegEx有什么问题/^[\p{L}\p{N}]+/u.当我的高级输入%openminded时正则表达式返回false.我需要它接受这种格式

%openminded
100%openminded
openminded 100%

我需要在表达式中添加什么?因此,即使用户%首先输入或任何特殊字符,它也会接受输入.

tch*_*ist 5

百分号不是\pS符号.\pP正如uniprops解释的那样, 这是一个标点符号:

$ uniprops %
U+0025 ‹%› \N{PERCENT SIGN}
    \pP \p{Po}
    All Any ASCII Assigned Basic_Latin Common Zyyy Po P Gr_Base Grapheme_Base Graph GrBase Other_Punctuation Punct Pat_Syn Pattern_Syntax PatSyn POSIX_Graph POSIX_Print POSIX_Punct Print Punctuation X_POSIX_Graph X_POSIX_Print X_POSIX_Punct
Run Code Online (Sandbox Code Playgroud)

您应该熟悉您最喜欢的角色所属的常规类别(可能还有脚本).以下是运行unichars的一些示例输出:

$ unichars -gs '[\pP\pS]' '\p{Block=Basic_Latin}'
U+0021 ? !  GC=Po SC=Common       EXCLAMATION MARK
U+0022 ? "  GC=Po SC=Common       QUOTATION MARK
U+0023 ? #  GC=Po SC=Common       NUMBER SIGN
U+0024 ? $  GC=Sc SC=Common       DOLLAR SIGN
U+0025 ? %  GC=Po SC=Common       PERCENT SIGN
U+0026 ? &  GC=Po SC=Common       AMPERSAND
U+0027 ? '  GC=Po SC=Common       APOSTROPHE
U+0028 ? (  GC=Ps SC=Common       LEFT PARENTHESIS
U+0029 ? )  GC=Pe SC=Common       RIGHT PARENTHESIS
U+002A ? *  GC=Po SC=Common       ASTERISK
U+002B ? +  GC=Sm SC=Common       PLUS SIGN
U+002C ? ,  GC=Po SC=Common       COMMA
U+002D ? -  GC=Pd SC=Common       HYPHEN-MINUS
U+002E ? .  GC=Po SC=Common       FULL STOP
U+002F ? /  GC=Po SC=Common       SOLIDUS
U+003A ? :  GC=Po SC=Common       COLON
U+003B ? ;  GC=Po SC=Common       SEMICOLON
U+003C ? <  GC=Sm SC=Common       LESS-THAN SIGN
U+003D ? =  GC=Sm SC=Common       EQUALS SIGN
U+003E ? >  GC=Sm SC=Common       GREATER-THAN SIGN
U+003F ? ?  GC=Po SC=Common       QUESTION MARK
U+0040 ? @  GC=Po SC=Common       COMMERCIAL AT
U+005B ? [  GC=Ps SC=Common       LEFT SQUARE BRACKET
U+005C ? \  GC=Po SC=Common       REVERSE SOLIDUS
U+005D ? ]  GC=Pe SC=Common       RIGHT SQUARE BRACKET
U+005E ? ^  GC=Sk SC=Common       CIRCUMFLEX ACCENT
U+005F ? _  GC=Pc SC=Common       LOW LINE
U+0060 ? `  GC=Sk SC=Common       GRAVE ACCENT
U+007B ? {  GC=Ps SC=Common       LEFT CURLY BRACKET
U+007C ? |  GC=Sm SC=Common       VERTICAL LINE
U+007D ? }  GC=Pe SC=Common       RIGHT CURLY BRACKET
U+007E ? ~  GC=Sm SC=Common       TILDE
Run Code Online (Sandbox Code Playgroud)

所以要么为你的班级添加正确的一般类别,比如

 [\pL\pN\p{Po}]
Run Code Online (Sandbox Code Playgroud)

或者只是添加你需要的特定字符.顺便说一句,任何想要的东西也\pL几乎总是也想要\pM.