Regex help

S

SpideyPKT

Help!

I'm trying to create a regex and I can't quite seem to get it right...

I'm trying to get several arguments out of a string which looks like:

args=['arg #1']
or
args=['arg #1', 'arg #2', 'arg #3']

I'd like to be able access the arguments via something like:
for(int i=1; i <= m.groupCount(); i++)
arg = m.group(i);


The closest pattern I've gotten is:
"args=\\[(?:\'(.*?)\',)*\\s*\'(.+)\'\\]"


My problem is that for a single argument, I get arg[1] = null and
arg[2] = "arg #1" and for 3 or more arguments i get arg[1] = arg #1 and
arg[2] = arg #2' , 'arg #3 so it has something to do with it greedily
grabbing the rest of the characters.

Any ideas???

Thanks in advance!
Brian
 
R

Roedy Green

My problem is that for a single argument, I get arg[1] = null and
arg[2] = "arg #1" and for 3 or more arguments i get arg[1] = arg #1 and
arg[2] = arg #2' , 'arg #3 so it has something to do with it greedily
grabbing the rest of the characters.

Any ideas???

tackle it as multiple problems.

find an arglist. Once you have that find the args, One you have that
process each arg.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

C pipe 1
RegEx 0
My regex kung-fu is not strong =( 0
Regex help 3
Regex replace problem 2
Creating a regex to get multiple values and print 0
Code help please 4
Think I May Have Found a Bug with wc -l 18

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top