How to find words containing a certain letter with Regular Expressions?

前端 未结 2 1180
耶瑟儿~
耶瑟儿~ 2020-12-20 13:44

I need a regular expression to find any words containing the letter \"y\".

This was my idea:

/\\bw*[y]\\w*\\b/

a word boundary, som

相关标签:
2条回答
  • 2020-12-20 14:26

    Not knowing what language you're using and guessing based on the syntax of your attempt, this should work:

    /\b\w*[Yy]\w*\b/g
    

    Without the "g" (for "global") option you'll only get the first match. Note also this matches on "y" in both upper and lower case.

    0 讨论(0)
  • 2020-12-20 14:26

    maybe try this:

    [a-zA-Z]*y[a-zA-Z]*
    

    This finds all words that have the letter 'y'.

    I hope I helped. I tested it on http://regexpal.com/

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