0

我的正则表达式

/^[\p{L}\p{N}][\p{L}\p{N} \.,;:\?!-“”‘’"']+$/u

正则表达式的目的

允许utf-8字符、数字、空格和自定义标点符号来验证文章标题

下面的这些输入不匹配,但如果标点符号并排,我也想要匹配?你能告诉我我的正则表达式的正确形式吗?注意:点和问号前面的反斜杠用于转义尝试。我也尝试过不逃跑。我不擅长正则表达式。我只能找到子部分然后尝试组合。谢谢。BR

输入不匹配

  1. “塞利姆”!'"':?-
  2. "'
  3. '"
  4. ?!
  5. 我还发现我不能以标点符号开头标题。示例“标题”日期不匹配
4

2 回答 2

1

更改为:

/^[\p{L}\p{N}“”‘’"'][\p{L}\p{N} .,;:?!\-“”‘’"']*$/u

NB: - must be escaped if it isn't in the first or last position within the character class. But . and ? doesn't need.

于 2013-03-29T14:39:04.530 回答
1

Are the square brackets within the regex characters you accept? If so, they need to be escaped.

/^[\p{L}\p{N}\]\[\p{L}\p{N} \.,;:\?!-“”‘’"']+$/u

If not, then you need to include the punctuation you'll allow inside the first character class.

于 2013-03-29T14:45:50.500 回答