regexp problem

Discussion in 'Perl Misc' started by Billy Patton, Jan 10, 2007.

  1. Billy Patton

    Billy Patton Guest

    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.
    Billy Patton, Jan 10, 2007
    #1
    1. Advertising

  2. Billy Patton

    John Bokma Guest

    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.


    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/
    John Bokma, Jan 10, 2007
    #2
    1. Advertising

  3. Billy Patton

    Billy Patton Guest

    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";
    Billy Patton, Jan 10, 2007
    #3
  4. Billy Patton

    DJ Stunks Guest

    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
    DJ Stunks, Jan 10, 2007
    #4
  5. Billy Patton

    Billy Patton Guest

    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
    Billy Patton, Jan 10, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Hurrell
    Replies:
    4
    Views:
    149
    James Edward Gray II
    Feb 14, 2007
  2. Mikel Lindsaar
    Replies:
    0
    Views:
    463
    Mikel Lindsaar
    Mar 31, 2008
  3. Joao Silva
    Replies:
    16
    Views:
    340
    7stud --
    Aug 21, 2009
  4. Uldis  Bojars
    Replies:
    2
    Views:
    185
    Janwillem Borleffs
    Dec 17, 2006
  5. Matìj Cepl

    new RegExp().test() or just RegExp().test()

    Matìj Cepl, Nov 24, 2009, in forum: Javascript
    Replies:
    3
    Views:
    169
    Matěj Cepl
    Nov 24, 2009
Loading...

Share This Page