@REGEX: behavior vs. documentation

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
The bevavior of @REGEX when groups are specified still does not match what the help says,

"Returns the number of matching groups in the string."

Code:
v:\> xsyntax.bat
Syntax: Perl
@regex[(a)|(b)|(c)|(d), dog] = 5

Syntax: Ruby
@regex[(a)|(b)|(c)|(d), dog] = 5

Syntax: GNU
@regex[(a)|(b)|(c)|(d), dog] = 5

Syntax: POSIX
@regex[(a)|(b)|(c)|(d), dog] = 5

Syntax: Java
@regex[(a)|(b)|(c)|(d), dog] = 5

Syntax: Grep
@regex[\(a\)\|\(b\)\|\(c\)\|\(d\), dog] = 5
 

rconn

Administrator
Staff member
May 14, 2008
10,097
85
#2
> The bevavior of @REGEX when groups are specified still does not match
> what the help says,
>
> "Returns the number of matching groups in the string."
We've already established in your previous dozen messages that the help is
misleading, and it will be updated.

@REGEX is returning the number of matching subexpressions, which in your
example is 5:

[0] => d
[1] =>
[2] =>
[3] =>
[4] => d

Rex Conn
JP Software
 
#3
On Sat, 28 Aug 2010 22:40:03 -0400, rconn <>
wrote:

|We've already established in your previous dozen messages that the help is
|misleading, and it will be updated.
|
|@REGEX is returning the number of matching subexpressions, which in your
|example is 5:
|
| [0] => d
| [1] =>
| [2] =>
| [3] =>
| [4] => d

Code:
%@regex[(a)|(b)|(c)|(d), dog]
I have no idea what you're saying above ... groups 1, 2, and 3 simply
weren't matched.

Code:
v:\> echo %@regex[(a)|(b)|(c)|(d),a]
5

v:\> echo %@regex[(a)|(b)|(c)|(d),ab]
5

v:\> echo %@regex[(a)|(b)|(c)|(d),abc]
5

v:\> echo %@regex[(a)|(b)|(c)|(d),abcd]
5
They're all the same ... not exactly enlightening to the user ... all
he learns is that there was a match and that he specified 5 groups
(the entire regex being group 0) the second of which he already knew.

If the regex is "(a)|(b)|(c)|(d)", onig_match() will **always** give
region->num_regs equal to 5, even if there's no match at all. It has
nothing to do with the string. Onig_search() only finds one match per
call.