airnet
airnet

Reputation: 2673

regex - using "+ " quantifier consecutively

Adding/removing the "+" doesn't change the output. But I don't get any errors either. what does "+" do here ?

/.{3}+/g

Upvotes: 1

Views: 73

Answers (3)

Jose Mar
Jose Mar

Reputation: 694

var re = /.{3}+/g;
^
SyntaxError: Invalid regular expression: /.{3}+/: Nothing to repeat at new RegExp (native)

This is what I get in nodejs (v.0.12.4)

Upvotes: 0

SergeyAn
SergeyAn

Reputation: 764

Use this regex debugger

It parsers the regex and describes it in detail

/.{3}+/g
    .{3}+ matches any character (except newline)
        Quantifier: {3}+ Exactly 3 times
    g modifier: global. All matches (don't return on first match)

Upvotes: 1

Charlie Stras
Charlie Stras

Reputation: 351

"+" is invalid here, maybe you mean

/(.{3})+/g

Upvotes: 2

Related Questions