Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i repeat regex

Tags:

regex

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
like image 372
o1-steve Avatar asked May 12 '16 18:05

o1-steve


People also ask

What does * do in regex?

The Match-zero-or-more Operator ( * ) This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. `*' represents this operator. For example, `o*' matches any string made up of zero or more `o' s.

How do you match a number in regex?

\d for single or multiple digit numbers To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.

What does regex match return?

The Match(String) method returns the first substring that matches a regular expression pattern in an input string. For information about the language elements used to build a regular expression pattern, see Regular Expression Language - Quick Reference.


1 Answers

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}.

like image 163
Ani Menon Avatar answered Oct 21 '22 03:10

Ani Menon