2012-12-06 15:11
浏览 90


I have seen similar problems but I cant quite get them to work for my scenario.

I am trying to use regex to find an optional wildcard between 2 strings. Here is an example of the strings that the regex does find correctly: not happy

if the string was: not very happy

The code must still match both cases.

The code I have is:


(happy and very would be variables)

Any help pointing me in the right direction would be very much appreciated.

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duai4512 2012-12-06 15:29

    Some tweaking may be required, but this would match up to two words in between "not" and "happy":

    解决 无用
    打赏 举报
  • doutan6286 2012-12-06 15:40

    This ...

    /not +([^ ]* +)?happy/

    And feel free to replace ? with {0,2} (for example) to match up to 2 words between not and happy.

    解决 无用
    打赏 举报

相关推荐 更多相似问题