java - How do I parse recurring pattern with regex -


I want to use regex to find unknown number arguments in a string. I think if I explain that it would be difficult, then see the example:

regex: @ISNULL (('. *?)', '(. *?)', '( . *?) '\)
String: @ISNULL (' 1 ',' 2 ',' 3 ')
Result:

This is working great. The problem starts when I search for the number of unknown numbers (2 more) is needed.

To find all the arguments that occur in the string, what changes do I need to make in regex?

So, if I parse this string "@ ISNULL ('1', '2', '3', '4', '5', '6')" / Code> I will get all the arguments

If you do not know the number of potential matches repeatedly, you need one in addition to capturing groups

In C #:

  string pattern = @ "@IsNUlL (('([^'] *) ',?) + \)"; String input = @ "@ ISNULL ('1', '2', '3', '4', '5', '6')"; Match Match = Reggae Match (input, pattern); If (match.Success) {Console.WriteLine ("Matched text: {0}", match value); {Console.WriteLine ("Group {0}: {1}", CTR, Match Group [CTR] Value for (int CTR = 1; CTR & lt; match.Groups.Count; ctr ++);); Intcaptacrate = 0; External (Capture Capture Group in the match. [Ctr]. Capters) {console.lightline ("Capture {0}: {1}", Capture Cater, Capt. CaptureCtr ++; For example, in Java (courtesy of code snippets):  

First of all, in the taste of the other reges, Find the part of the string you need:

  pattern regex = Pattern.compile ("@ ISNULL \ \ (('([^'] *) ',) + \\?)" ); // or, using non-capturing groups: // pattern regex = Pattern.compile ("@ ISNULL \\ (?: '(?: [^'] *) ',?) + \\)") ; Matcher regexMatcher = regex.matcher (subject string); If (regexMatcher.find ()) {ResultString = regexMatcher.group (); }  

Then use any other reggae to find and iterate your matches:

  list & lt; String & gt; MatchList = New Arrestist & lt; String & gt; (); Try {pattern regex = Pattern.compile ("'([^'] *) ''); Matcher regexMatcher = regex.matcher; ResultString; while (regexMatcher.find ()) {matchList.add (regexMatcher.group (1 ));}  

Comments