0

I'm looking to make a regex with an operator that applies to a whole word. For example, I want the word hello to be optional. Instead of having h?e?l?l?o?, I am wondering if it is possible to write something like (hello)?*.

*Note that (hello)? does not work for my case since I do not want hello to be returned in the matches.

4

1 回答 1

5

我怀疑你想要一个非捕获组,这是?:在组开始时使用的:

(?:hello)?

有关更多详细信息,请参阅MSDN 分组构造指南

于 2013-07-03T06:48:49.440 回答