S
SpideyPKT
I need some help with a regex I'm trying to get working. I'm trying to
write a regex which will handle a variable number of args in a string.
It will look something like this:
args=['token 1']
or
args=['token 1', 'token 2']
or
args=['token 1', 'token 2', 'token 3']
and so on...
I'm trying to write it so that I can get the tokens with something like
this:
while(true)
try {
tokens.add(m.group(i));
i++;
catch(IndexOutOfBoundsException e) {break;}
}
The closest I got to this correctly working was:
"args=\\[(?:\\s*\'(.*?)\',)*\\s*(?:\'(.+?)\')\\]\\s*". The problem I'm
having is that with the single argument case, I get 2 tokens, the first
one is null, the second is 'token 1'.
The 2 argument case works fine, but the case of 3+ arguments puts
'token 1' in the first toekn and everything else into the second token,
so I know I've got a problem using a greedy selector but I can't figure
out where it is.
Any ideas?
write a regex which will handle a variable number of args in a string.
It will look something like this:
args=['token 1']
or
args=['token 1', 'token 2']
or
args=['token 1', 'token 2', 'token 3']
and so on...
I'm trying to write it so that I can get the tokens with something like
this:
while(true)
try {
tokens.add(m.group(i));
i++;
catch(IndexOutOfBoundsException e) {break;}
}
The closest I got to this correctly working was:
"args=\\[(?:\\s*\'(.*?)\',)*\\s*(?:\'(.+?)\')\\]\\s*". The problem I'm
having is that with the single argument case, I get 2 tokens, the first
one is null, the second is 'token 1'.
The 2 argument case works fine, but the case of 3+ arguments puts
'token 1' in the first toekn and everything else into the second token,
so I know I've got a problem using a greedy selector but I can't figure
out where it is.
Any ideas?