0

我知道这个问题已经以至少 100 种不同的方式被问了至少 100 次,但我真的很难将我在此找到的所有东西拼凑在一起,以创造我需要的东西。

我需要一个可以在匹配这些字符的 XML 模式限制标记内使用的正则表达式 -

%&()"''*+,-./:;<=>?_#~@!$^[]{}0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ

作为一个完整的字符串,而不是单个单词或字符。它可以包含空格,但不能包含制表符空格或返回键字符。

这是我到目前为止所拥有的 -[A-Za-z0-9$-/:-?@#{-~!^_\'\[\] *]

提前致谢,

灰。

4

1 回答 1

1

[..] is a character set, and will match any single character given it is in the set. If you want to match a while string, then you need repetition * will match zero or more and + will match one or more. Since you want to match the entire string you also need to anchor your expression, you can do this with ^ for start of string and $ for end of string.

So the following regex will match star of string one or more characters from the given set end of string:

^[A-Za-z0-9$-/:-?@#{-~!^_\'\[\] *]+$

If you are interested in learning about regex you might want to read up on the basics there are lots of sites with tons of information, such as this one.

于 2013-05-03T10:48:45.520 回答