正则表达式不应该只是数字,必须允许包括换行符在内的所有字符

时间:2014-10-08 06:00:41

标签: regex

我正在尝试编写正则表达式,不应该只是数字,必须允许所有字符,包括换行符。

我尝试了以下案例:

  1. /[^0-9]/g;

    在这种情况下,如果我输入换行符,它就不起作用,然后尝试如下

  2. /^((?!www\.).)*$/

    在这种情况下,如果我像这样输入

    45454545
    45454545
    dfdfdfdfdfdf
    

    它无法正常工作。我认为这里只匹配一行,而不是整段。

  3. 你能告诉我正则表达式吗?

2 个答案:

答案 0 :(得分:0)

我想你想要这样的东西,

[\s\S]*?[^\d\n\r][\s\S]*

答案 1 :(得分:0)

试试/^(?!\d+$).*$/s。 这会匹配abc1aa1等内容,但不会匹配123

说明:

^ # assert start of string
(?! # assert the string is NOT all digits:
    \d+ # match any number of digits
    $ # and end of string
)
.* # since the previous assertion did not fail, simply match all available text
相关问题