Reputation: 331
I have the following regex:
"(.+?)",.+?},\s.+?:\s
I would like to know if there is a way to repeat this regex, so i don't need to write it several times like this:
"(.+?)",.+?},\s.+?:\s"(.+?)",.+?},\s.+?:\s"(.+?)",.+?},\s.+?:\s
Upvotes: 12
Views: 41635
Reputation: 28209
Put the regEx block in ()
and add *
or +
.
*
0 to any number of times.
+
1 to any number of times.
{n}
'n' times.
{n,}
at-least 'n' times.
(?: ... )
is called non-capturing group
Non-capturing parentheses group the regex so that you can apply regex operators, but do not capture anything.
Eg:
[0-9]{1}
this means 1 digit(0-9)
[0-9]+
this means at-least one digit(0-9).
[0-9]*
no digits or any number of digits(0-9).
Since you wanted "(.+?)",.+?},\s.+?:\s"(.+?)",.+?},\s.+?:\s"(.+?)",.+?},\s.+?:\s
,
you may do it like this : ("(.+?)",.+?},\s.+?:\s){3}
.
Upvotes: 34