List Info

Thread: repetition quantifier and named group




repetition quantifier and named group
user name
2006-10-11 13:55:37
I have a little question: is it possible to use a repatition
quantifier
like "" but instead of "n" using a
reference to a named group? Ex.
{k<name>}

For example i need to detect a pattern like this:
"3;string;string;string;" or
"2;string;string;"

I had tryed using this patern "(d+);([^;]+;)"
or a named
equivalent version
"(?<howmany>d+);([^;]+;){k<howmany>}"
; but without
success. I think than "" can accept only a
number as "n".

Is there a workaround for doing this?

I hope you can help me, thanks a lot
Diego


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---

repetition quantifier and named group
user name
2006-10-18 20:26:46
Archimede wrote:
> I have a little question: is it possible to use a
repatition quantifier
> like "" but instead of "n" using
a reference to a named group? Ex.
> {k<name>}
>
> For example i need to detect a pattern like this:
> "3;string;string;string;" or
"2;string;string;"
>
> I had tryed using this patern
"(d+);([^;]+;)" or a named
> equivalent version
"(?<howmany>d+);([^;]+;){k<howmany>}"
; but without
> success. I think than "" can accept only a
number as "n".
>
> Is there a workaround for doing this?

In Perl, this can be done by using an embedded code
construct
(??), like:

    (d+)(??{ "(;[^;]+){$1}" })

Or we can use some more regexes to do it, like using 'c',
'g' modifiers
and the 'G' anchor, i.e.:

while ( $str =~ /(d+)/g ) {
    my $num = $1;
    $str =~ /G((?:;[^;]*){$num})/gc and print
"$num$1";
}

Dont know how other tools handle this though.

Xicheng


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://grou
ps-beta.google.com/group/regex
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )