9

I have seen +? a lot in regex, but I'm not sure what it really stands for. I know + means 1 or more, and ? means 0 or 1. So does +? means 0 or more? In that case, why not just use *, which means 0 or more?

I just need to know if +? means 0 or more, or it means something different. Then I'll delete this question if it's too annoying.

3
  • It means "one or more" - preferably as few as possible (shortest match). Commented Sep 26, 2015 at 1:55
  • 1
    ? has different meanings depending on where it appears. After a + or a * or another ? it means “non-greedy”. Commented Sep 26, 2015 at 1:56
  • @jessica The duplicate targets have multiple examples, plus this question: stackoverflow.com/questions/32491947 Commented Sep 26, 2015 at 2:01

1 Answer 1

15

The ? makes the + "lazy" instead of "greedy". This means it tries to match as few times as possible, instead of trying to match as many times as possible.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.