How can I create a create a java regular expression for a comma separator list -


"post-text" itemprop = "text">

How do I create a Java regular expression for a comma separated list?

(3) (3, 6) (3, 6)

I tried, but it does not match anything:

  Pattern.compile ("\\ (\\ S [,] + \ \ ")  

And how can I get" 3 "or" 3 "and" 6 "in my code from the michter class?

< P>

validation regex

You can try this meta-regex approach for clarity:

  string letters N = "& lt; part (?:, Part) * & gt;" ("", "\\" *. ("", "Re \", "re \", "^ \\ s * ( ;); ++ "); Println (pattern); / *** This pattern is (\ s * [^ \ s * (,)] + \ s * (?: \ S *, \ s * [^ \ S * (,)] + \ s *) * \ S * \) **** /  

part pattern [^ \ s ( ,]] + , that is, one or more things but white space, brackets and commas are called this denoted square squares [aeiou] 5 vowels Matches any of the letters; [^ aeiou] matches everything (including dishes, but numbers, symbols, white space).

+ Duplication also ++ (?: ...) A non-capturing for construction optimization There is also a group.

context

  • ,

test and partition

We can test the pattern as follows:

  string [] trials = {"(1,3,6)", "(x, y !, a + b = c) "," ([,,  

This prints:

  (1,3,6) = [1, 3, 6] (x, y !, a + b = C) = [X, Y!, A + B = C] (1, 3, 6) = [1, 3, 6] (1,3,6,) No matching (()) No matching (, ) (Oh, Mary, God) = (Oh, mine, God) no match ([], <<) = [[], ] (!!, ???? , ++) = [!!, ????, ++]  

Use String.split to touch the bracket After all the parts of the string [] .


Comments