Re: Regexp for variable length tags



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
.



Relevant Pages

  • Re: Regexp for variable length tags
    ... > I am processing some data that has a up to three key-value pairs ... The keys can be "ADD, REM, EQD". ...
    (comp.lang.perl.misc)
  • Regexp for variable length tags
    ... The keys can be "ADD, REM, EQD". ... I'm trying to find a regular expression that will split this apart into separarate sections in one step. ...
    (comp.lang.perl.misc)
  • Re: I want to know the pros and cons of TCL....
    ... key-value pairs are ... added, and keys can appear more than once, with other keys between ... It does not map to any other internal data structure that I've seen. ...
    (comp.lang.tcl)
  • Re: I want to know the pros and cons of TCL....
    ... key-value pairs are ... added, and keys can appear more than once, with other keys between ... thread in the future I just wanted to clarify that dicts do maintain ...
    (comp.lang.tcl)