D
D
Daniil Igorevich2016-03-08 20:43:22
JavaScript
Daniil Igorevich, 2016-03-08 20:43:22

How did the quantifier affect the parenthesis in the regular expression?

var re = /#([a-f0-9]{3}){1,2}/gi;

var str = "color: #3f3; background-color: #AA00ef; and: #abcd";

alert( str.match(re) );

Printed #3f3, #AA00EF and #abc. How does {1,2} affect the bracket ([a-f0-9]{3})?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2016-03-09
@Petr_Anisimov

Well, then the first combination should occur 1 or 2 times. So either 3 or 6 digits

K
kompi, 2016-03-08
@kompi

Open any online regular checker and read the explanation section. For example, on the site regex101.com

K
keslo, 2016-03-08
@keslo

I dare to suggest that it {1,2}affects like "the fact that in brackets there is 1 time or 2 times in a row.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question