Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > regexp problem

Reply
Thread Tools

regexp problem

 
 
Billy Patton
Guest
Posts: n/a
 
      01-10-2007
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.
 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      01-10-2007
Billy Patton <(E-Mail Removed)> wrote:

> 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

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
 
 
 
Billy Patton
Guest
Posts: n/a
 
      01-10-2007
Billy Patton wrote:
> 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";

 
Reply With Quote
 
DJ Stunks
Guest
Posts: n/a
 
      01-10-2007

Billy Patton wrote:
> 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

 
Reply With Quote
 
Billy Patton
Guest
Posts: n/a
 
      01-10-2007
DJ Stunks wrote:
> Billy Patton wrote:
>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new RegExp().test() or just RegExp().test() Matěj Cepl Javascript 3 11-24-2009 02:41 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Ruby 1.9 - ArgumentError: incompatible encoding regexp match(US-ASCII regexp with ISO-2022-JP string) Mikel Lindsaar Ruby 0 03-31-2008 10:27 AM
Programmatically turning a Regexp into an anchored Regexp Greg Hurrell Ruby 4 02-14-2007 06:56 PM
RegExp.exec() returns null when there is a match - a JavaScript RegExp bug? Uldis Bojars Javascript 2 12-17-2006 09:59 PM



Advertisments