regex: required character in brackets

后端 未结 3 821
北荒
北荒 2021-01-14 16:43

How do I search for a string that contains only chars from a set including x, and require it to contain x? e.g. [a-z]+ but not matching if it doesn

相关标签:
3条回答
  • 2021-01-14 17:14

    Assuming you want to match a string of only x,y or z, match start (^) followed by zero or more y or z ([yz]*) followed by an x followed by zero or more x, y or z ([xyz]*) followed by end ($)

    ^[yz]*x[xyz]*$
    

    If you are trying to match [a-z] but with an x in there somewhere, then this should do it

    ^[a-z]*x[a-z]*$
    
    0 讨论(0)
  • 2021-01-14 17:20

    try something like this

    ^[a-z]*x[a-z]*$

    0 讨论(0)
  • 2021-01-14 17:36

    [a-z]*x[a-z]* should do the trick.

    0 讨论(0)
提交回复
热议问题