Regular Expression (\S+?) vs (\S+))

This question already has an answer here:

  • Reference - What does this regex mean? 1 answer
  • How to match “anything up until this sequence of characters” in a regular expression? 9 answers
  • Greedy vs. Reluctant vs. Possessive Quantifiers 7 answers
  • In a regex, what changes when you add a question mark to .+ 2 answers
  • My regex is matching too much. How do I make it stop? 4 answers

  • The first means match a single character that is a non-whitespace character, between one and unlimited times, as many times as possible, giving back as needed (greedy) .

    The second means Match a single character that is a non-whitespace character, between one and unlimited times, as few times as possible, expanding as needed (lazy) .

    The difference is greedy or lazy repetition. From the Regex Buddy help file:

    A greedy quantifier will first try to repeat the token as many times as possible, and gradually give up matches as the engine backtracks to find an overall match. A lazy quantifier will first repeat the token as few times as required, and gradually expand the match as the engine backtracks through the regex to find an overall match.

    The differences can be seen in the images below:

    贪婪的量词

    懒惰的量词

    链接地址: http://www.djcxy.com/p/76904.html

    上一篇: 清晰的认识量化值

    下一篇: 正则表达式(\ S +?)vs(\ S +))