Regex to first occurrence only?

前端 未结 4 1109
暖寄归人
暖寄归人 2020-11-29 11:18

Let\'s say I have the following string:

this is a test for the sake of testing. this is only a test. The end.

and I want to se

4条回答
  •  借酒劲吻你
    2020-11-29 12:06

    The regex is greedy meaning it will capture as many characters as it can which fall into the .* match. To make it non-greedy try:

    this(.*?)test

    The ? modifier will make it capture as few characters as possible in the match.

提交回复
热议问题