[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] regex gurus
So, you have this:
my $condstring="include_1 (f7 ne \'ce\' and f10 ne \'r\' and f1 ne
\'ce\' and f8 ne \'lg\' and f8 ne \'li\' and f8 ne \'lj\' and f8 ne
\'lr\' and f8 ne \'lu\' and f8 ne \'lv\' and f8 ne \'tl\' and f8 ne
\'ta\' and(f4 eq \'e\' or f4 eq \'g\' or f4 eq \'w\')) ";
And you want to break it up so that you get an array something like this:
@condarr = ["f7", "ne", "\'ce\'", "and", ..., "eq", "\'w\'"];
???
If so, a basic split using "/ /" should do it:
@condarr = split / /, $condstring;
But, you mentioned grouping the array based on ()s.
@condarr = [
include_1,
[
f7 ne \'ce\' and f10 ne \'r\' and f1 ne \'ce\' and f8 ne
\'lg\' and f8 ne \'li\' and f8 ne \'lj\' and f8 ne \'lr\' and f8 ne
\'lu\' and f8 ne \'lv\' and f8 ne \'tl\' and f8 ne \'ta\' and,
f4 eq \'e\' or f4 eq \'g\' or f4 eq \'w\',
]
]
(Probably not syntactically correct - done by hand...)
Is something like this closer to what you are looking for?
A split based on the parethesis characters might do it, but you'd have
to make sure the regexp would handle nested parenthesis correctly...
Dan
On Fri, Feb 19, 2010 at 10:45, Jay Swackhamer <Jay@reboottheuser.com> wrote:
> In the string below, it's from a parameter file.
>
> I need to break it out by what's the longest string between the '(' and the
> ')'
> and then the shorter strings between '(' and ')' , then the and/or's so I
> can translate/process the logic.
>
> the include_1 would be a condition name, and the f7/f10/f8 etc are field
> names that are substrings of lines of data.
>
> --
> Jay Swackhamer
> Reboot The User
> 402-933-6449
> http://www.reboottheuser.com
> http://www.cafepress.com/rtu
> http://stores.ebay.com/RebootTheUser
> http://www.hotr.com
>
>
> Quoting Dave Burchell <evaddnomaid@gmail.com>:
>
>> Sure Jay, I'm no guru but I use regex whenever I can.
>>
>> What do you mean when you say "based on what is between '( )'"?
>>
>> - Dave
>>
>> On Fri, Feb 19, 2010 at 10:17 AM, Jay Swackhamer
>> <Jay@reboottheuser.com>wrote:
>>
>>>
>>> Looking at examples, not getting it done.
>>>
>>> Any regex gurus out there that can give me a tip on taking a string and
>>> splitting into groups based on what is between '( )'
>>>
>>> So I can take condstring, split it into an array by whats grouped in (),
>>> then take each element and split out the rest of the () groups.
>>> i.e.
>>>
>>> my $condstring="include_1 (f7 ne \'ce\' and f10 ne \'r\' and f1 ne
>>> \'ce\'
>>> and f8 ne \'lg\' and f8 ne \'li\' and f8 ne \'lj\' and f8 ne \'lr\' and
>>> f8
>>> ne \'lu\' and f8 ne \'lv\' and f8 ne \'tl\' and f8 ne \'ta\' and(f4 eq
>>> \'e\'
>>> or f4 eq \'g\' or f4 eq \'w\')) ";
>>>
>>> @condarr = split /(\).*\))/, $condstring;
>>>
>>>
>>> --
>>> Jay Swackhamer
>>> Reboot The User
>>> 402-933-6449
>>> http://www.reboottheuser.com
>>> http://www.cafepress.com/rtu
>>> http://stores.ebay.com/RebootTheUser
>>> http://www.hotr.com
>>>
>>>
>>>
>>> _______________________________________________
>>> Omaha-pm mailing list
>>> Omaha-pm@pm.org
>>> http://mail.pm.org/mailman/listinfo/omaha-pm
>>>
>>
>>
>>
>> --
>> Dave Burchell
>>
>
>
>
> _______________________________________________
> Omaha-pm mailing list
> Omaha-pm@pm.org
> http://mail.pm.org/mailman/listinfo/omaha-pm
>
--
***************** ************* *********** ******* ***** *** **
"Quis custodiet ipsos custodes?"
(Who can watch the watchmen?)
-- from the Satires of Juvenal
"I do not fear computers, I fear the lack of them."
-- Isaac Asimov (Author)
** *** ***** ******* *********** ************* *****************