Regular Expression, pattern matching in xsd

后端 未结 3 525
梦谈多话
梦谈多话 2020-12-16 15:58

I was wondering how to make a regular expression for any character except * and + . I\'ve tried ([^*+]) and (\\[^*+]) but

3条回答
  •  不知归路
    2020-12-16 16:34

    You were close:

    [^*+]
    

    enter image description here

    Notice that there's no need for escaping those characters inside square brackets, because they have no special meaning there.

    EDIT: according to http://www.regular-expressions.info/charclass.html:

    Note that the only special characters or metacharacters inside a character class are the closing bracket (]), the backslash (), the caret (^) and the hyphen (-). The usual metacharacters are normal characters inside a character class, and do not need to be escaped by a backslash. To search for a star or plus, use [+*]. Your regex will work fine if you escape the regular metacharacters inside a character class, but doing so significantly reduces readability.

    So the problem is not in the character escaping. Maybe you need to match all those occurences. In that case, look up @Cfreak's answer.

提交回复
热议问题