Lazy quantifier {,}? not working as I would expect

I have a problem with lazy quantifiers. Or, most likely, I misunderstand how I should use them.

Testing on Regex101 My test line can say:123456789D123456789

.{1,5} corresponds to 12345

.{1,5}? corresponds to 1

I'm fine with both matches.

.{1,5}?Dmatches 56789D!! I expect it to fit9D

Thanks for clarifying this.

+4
source share
3 answers

, , / . "" "" , , . , , , ( ).

regex . , , , , , .

, .{1,5}D: 1 D . D 1, regex 12 D. 2 3, 5 . 12345, D. , , .

5. 5, 5D, , 56D, , 567D, , 5678D - , 56789D - Bingo! - .

, "" , .

regex101.com:

enter image description here

: .{1,5}? 1 ( ), 1, , . , D.{1,5}?, D1 D6 123456789D12345D678904.

Fun Fact 2. .NET "" RightToLeft. .{1,5}?D 9D, . .

3. .NET, (?<=(.{1,5}?))D 9 1, 123456789D . - , lookbehind .NET regex (.NET , lookbehind, ). Java (?<=(.{1,5}))D ( ) 9, , .

: , 1 , D,

/.D/
+8

, , , {1,5}? 1 ( .) , , , .

\d + , , D.

(\d+)(\d{1,5}D) 9D

, (5)

(\d+?)(\d{1,5}D) 56789D

, , .

0

.{1,5}?D

123456789D123456789
    ------

, 9D, "- ".

, ?

D.{1,5}?

?

! ,

123456789D123456789
         --

, ?

. -, , , . , - ,

123456789D123456789
    ------

123456789D123456789
     -----
123456789D123456789
      ----
...
123456789D123456789
        --

regex , "Lazy quantifiers".

D.{1,5}?,

123456789D123456789
         ---
123456789D123456789
         ----
...
123456789D123456789
         ------

123456789D123456789
         --
0

All Articles