regexp problem

B

Billy Patton

I'm using regexp coach to assist me but more heads would be helpful

Here is a sample of the data

dogs,10,cats
dogs,[20,30],cats
dogs,[40,[50,60]],cats

I'm looking to validate input data (above) based on reg expression.
To verify legal input.
Ignore the dogs and cats, its just a filler

I currently have 3 different lines that I would like to combine
\d+,?
\[\d+,\d+\],?
[\d+,\[\d+,\d+\]\],?

Here is what I would like to do but regex coach isn't liking it
(\d+,?|\[\d+,\d+\],?|[\d+,\[\d+,\d+\]\],?)

Since the () allows for grouping, I was hoping the | would or it within
the group.
 
J

John Bokma

Billy Patton said:
I'm using regexp coach to assist me but more heads would be helpful

Here is a sample of the data

dogs,10,cats
dogs,[20,30],cats
dogs,[40,[50,60]],cats

I'm looking to validate input data (above) based on reg expression.
To verify legal input.

Most of the time when input involves [] (or () or {}) that must match
(balance) you want to step away from regex and use other options.

I probably would use Parse::RecDescent
 
B

Billy Patton

Billy said:
I'm using regexp coach to assist me but more heads would be helpful

Here is a sample of the data

dogs,10,cats
dogs,[20,30],cats
dogs,[40,[50,60]],cats

I'm looking to validate input data (above) based on reg expression.
To verify legal input.
Ignore the dogs and cats, its just a filler

I currently have 3 different lines that I would like to combine
\d+,?
\[\d+,\d+\],?
[\d+,\[\d+,\d+\]\],?

Here is what I would like to do but regex coach isn't liking it
(\d+,?|\[\d+,\d+\],?|[\d+,\[\d+,\d+\]\],?)

Since the () allows for grouping, I was hoping the | would or it within
the group.
Got it,
Had my data wrong in regex coach, When i entered it in a perl script I
got it working, then went back to regex coach and it worked then
Here's what I had.

$x = 'dogs,10,cats';
$y = 'dogs,[20,30],cats';
$z = 'dogs,[40,[50,60]],cats';
$x =~ /^dogs,(\d+,?|\[\d+,\d+\],?|\[\d+,\[\d+,\d+\]\],?),?/;
print "$1\n";
$y =~ /^dogs,(\d+,?|\[\d+,\d+\],?|\[\d+,\[\d+,\d+\]\],?),?/;
print "$1\n";
$z =~ /^dogs,(\d+,?|\[\d+,\d+\],?|\[\d+,\[\d+,\d+\]\],?),?/;
print "$1\n";
 
D

DJ Stunks

Billy said:
Here is a sample of the data

dogs,10,cats
dogs,[20,30],cats
dogs,[40,[50,60]],cats

I'm looking to validate input data (above) based on reg expression.
To verify legal input.
Ignore the dogs and cats, its just a filler

If you're trying to validate, and you want any help at all, then you
need to tell us what input is valid (duh). Maybe I'm just cranky
today, but it seems like common sense to include this kind of
information when posing a question like this.

does the input have to start with dogs? does it have to end with cats?
do any numbers in between have to be two digits? do they have to be
multiples of 10? do the square brackets have to be balanced? does
there have to be at least one two digit number? if there's more than
one number does it have to be bracketed? etcetera etcetera etcetera.

<rant>
sometimes I can't believe people that post questions here are
programmers. programming means, in essence, a methodical, linear,
step-by-step approach to problem solving. 90% of the questions people
ask here are just nonsense and bely total disorganization. I'm always
amazed that their scripts work at all.
</rant>

yep: cranky. sorry(-ish). hahaha

-jp
 
B

Billy Patton

DJ said:
Billy said:
Here is a sample of the data

dogs,10,cats
dogs,[20,30],cats
dogs,[40,[50,60]],cats

I'm looking to validate input data (above) based on reg expression.
To verify legal input.
Ignore the dogs and cats, its just a filler

If you're trying to validate, and you want any help at all, then you
need to tell us what input is valid (duh). Maybe I'm just cranky
today, but it seems like common sense to include this kind of
information when posing a question like this.

does the input have to start with dogs? does it have to end with cats?
do any numbers in between have to be two digits? do they have to be
multiples of 10? do the square brackets have to be balanced? does
there have to be at least one two digit number? if there's more than
one number does it have to be bracketed? etcetera etcetera etcetera.

<rant>
sometimes I can't believe people that post questions here are
programmers. programming means, in essence, a methodical, linear,
step-by-step approach to problem solving. 90% of the questions people
ask here are just nonsense and bely total disorganization. I'm always
amazed that their scripts work at all.
</rant>

yep: cranky. sorry(-ish). hahaha

-jp

After typing blow, I noticed that i didn't include my regexp witht he
question :) The mind sees what it wants:)
Well cranky :)
Most of the group wants a limited amount, reduced to the smallest amount
of data. That is what I provided, data and a regexp, not my validation
routines and data. Drastic overkill! The problem resided with
combining 3 regexp's into one.
I did solve the problem and the problem only consisted of the data
between dogs and cats
The main problem was that I didn't know if I could the '|' working
within the (). I use the () for grouping not for capturing
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top