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
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.
\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.
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.
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}
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With