Re: Regexp for variable length tags
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Mon, 18 Jul 2005 20:24:39 GMT
Jon Burroughs wrote:
> I am processing some data that has a up to three key-value pairs
> concatenated together. The keys can be "ADD, REM, EQD". Values are
> variable length.
>
> There will always be an "ADD" section, followed by 0 to 1 "REM"
> sections, followed by 0 to 1 "EQD" sections. For example:
> ADDxxxxxxxxREMyyyyyEQDzzzzz
>
> I'm trying to find a regular expression that will split this apart into
> separarate sections in one step.
>
> So far, I have this:
>
> $rec =~ /(ADD.+)(REM.+)(EQD.+)/;
>
> But, this only works if I know the record has all three tokens.
>
> This gobbles too much:
> $rec =~ /(ADD.+)(REM.+)?(EQD.+)?/;
>
> Any ideas?
Try using non-greedy quantifiers.
perldoc perlre
John
.
- References:
- Regexp for variable length tags
- From: Jon Burroughs
- Regexp for variable length tags
- Prev by Date: Re: Creating an array from file input
- Next by Date: Re: copy contructor
- Previous by thread: Regexp for variable length tags
- Next by thread: Re: Regexp for variable length tags
- Index(es):
Relevant Pages
|