Re: Regex repeating capture



Jay wrote:
Howdy,

I'm trying to break an input string into multpile pieces using a series of delimiters that start with an asterisk. Following the asterisk is a mulitple character identifier immediately followed by a
data string of variable length. The input string may contain more than one identifier anywhere in the string. In all, there are 50+ identifiers to search for and the asterisk is allowed to part of the data string as long as it isn't defined as an identifier (it would be treated as another identifier at that point).

Here is a simple example:
*CZ1 2.3 4-56 *fuuuS24364 08 23 72

I'd like to break this into
CZ
1 2.3 4-56
fuuu
S24364 08 23 72

I have tried the pattern (?:\*(CZ|fuuu)(.*)), which produces the
following ouput:
CZ
1 2.3 4-56 *fuuuS24364 08 23 72

How can I force it to repeat the capturing?

Thanks,
Jay

my $line = '*CZ1 2.3 4-56 *fuuuS24364 08 23 72';
$line =~ /\*(CZ)(.+)\s+\*(fuuu)(.+)\s*$/;

# $1 = CZ
# $2 = 1 2.3 4-56
# $3 = fuuu
# $4 = S24364 08 23 72

Todd
.



Relevant Pages

  • Regex repeating capture
    ... series of delimiters that start with an asterisk. ... data string of variable length. ... The input string may contain more than ... one identifier anywhere in the string. ...
    (comp.lang.perl.misc)
  • Re: Regex repeating capture
    ... an identifier, otherwise it is considered another identifier. ... to split your string on the asterisk as a first step. ... public bool StartsWith ( ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Regex repeating capture
    ... series of delimiters that start with an asterisk. ... data string of variable length. ... one identifier anywhere in the string. ...
    (comp.lang.perl.misc)
  • Re: Strip everything out of a string expect numbers.
    ... >> string that is stored in a buffer that can be any of the following ... > easy way to skip over all the leading non-digits. ... Here is the sscanf function that almost works ... for "store", throw away an asterisk, which may or may not be there, get ...
    (comp.lang.c)
  • Re: [C] strange bug in code
    ... >The correct program output was a string of ASCII codes that might ... >in the context of a function header? ... If all you did was move the asterisk around the way you've shown, ...
    (alt.comp.lang.learn.c-cpp)