Regular Expression Wildcard Matching

前端 未结 9 1502
甜味超标
甜味超标 2020-12-15 04:13

I have a list of about 120 thousand english words (basically every word in the language).

I need a regular expression that would allow searching through these words

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 04:56

    Unless you want some funny behaviour, I would recommend you use \w instead of .

    . matches whitespace and other non-word symbols, which you might not want it to do.

    So I would replace ? with \w and replace * with \w*

    Also if you want * to match at least one character, replace it with \w+ instead. This would mean that ben* would match bend and bending but not ben - it's up to you, just depends what your requirements are.

提交回复
热议问题