Dett Dett - 1 year ago 66
Java Question

Trying to create a regexp

I have a string which I want a string to parse via Java or Python regexp:

something (\var1 \var2 \var3 $var4 #var5 $var6 *fdsfdsfd @uytuytuyt fdsgfdgfdgf aaabbccc)

The number of
is unknown. Their exact names are unknown. Their names may or may not start with "\" or "$", "*", "@" or "#" and there're delimited by whitespace.

I'd like to parse them separately, that is, in capture groups, if possible. How can I do that? The output I want is a list of:

[\var1 , \var2 , \var3 , $var4 , #var5 , $var6 , *fdsfdsfd , @uytuytuyt , fdsgfdgfdgf , aaabbccc]

I don't need the java or python code, I just need the regexp. My incomplete one is:


Answer Source


In this regex you are capturing the string containing all the variables. split it based on whitespace since you are sure that they are delimited by whitespace.

m ='something\s\((.+)\)', input_string)
if m:
    list_of_vars =
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download