regex to match entire words containing only certain characters

后端 未结 4 1355
無奈伤痛
無奈伤痛 2021-01-18 06:01

I want to match entire words (or strings really) that containing only defined characters.

For example if the letters are d, o, g

4条回答
  •  耶瑟儿~
    2021-01-18 06:32

    The following regex represents one or more occurrences of the three characters you're looking for:

    [dog]+
    

    Explanation:

    The square brackets mean: "any of the enclosed characters".

    The plus sign means: "one or more occurrences of the previous expression"

    This would be the exact same thing:

    [ogd]+
    

提交回复
热议问题