Hi,

i have a string that i want to match to a regular expression. The string is
methodName(paraT1 para1, paraT2.name2 para2, paraT3.name3 para3)
Inside the () there can be multiple of "aaa.bbb ccc" and "ddd eee" patterns

The regular expression i wrote was :

(\w)(\s)((((\w.\w)\s(\w))|((\w)\s(\w)))(\s\,\s(((\w.\w)\s(\w))|((\w)\s(\w))))*)

and the I get the first and the last (parameterType para) pattern but not the ones inbetween. How do i get the middle expression.

appreciate a reply
thanks in advance

how do i repeat the regular expression section
(\s\,\s(((\w.\w)\s(\w))|((\w)\s(\w*))))

Your first question leads to named groups. To capture something specific it is easier to give it a name.

\w+\((?<first>[\w\s\.])+,(?<second>[\w\s\.])+,(?<third>[\w\s\.])+\)

Your second question could be reduced to

,?[\w\s\.]+

.

What language are you using to run your regex?

Or

(?<=\()((?:,?)[\w\s\.]+){3}(?=\))

to target all items between the parentheses.

1) Old post
2) This is Java, so RegEx is being used in Java
3) I am not sure but in Java, iirc, your RegEx string needs to specify leading and ending part with matches() method. Not sure about RegEx class.

A quick check against the Java engine in RegexBuddy shows my first re named grouping is different somehow.

Favorite language/favorite tool!

The third one works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.