@REGEX: behavior vs. documentation

May 20, 2008
11,400
99
Syracuse, NY, USA
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
12,344
149
> 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
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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.
 
Similar threads
Thread starter Title Forum Replies Date
F %@regex["^-","-a"] returns 0, "^-" =~ "-a" is false (no match) Support 4
JohnQSmith Regex renaming Support 2
vefatica TPIPE: unbalanced escaped quotes in a regex? Support 5
rps Regex problem: \xnn not recognized as a hex character Support 0
old coot Regex problem: \xnn not recognized as a hex character Support 12
R Regex using ^ Support 2
T Regex engine doesn't recognize native DOS line endings Support 2
P Simple RegEx copy Support 9
samintz WAD Regex Analyzer Support 1
D How to? Use typed envars using regex. Support 3
P Renaming with a RegEx Support 1
R How to? use @everything perl regex Support 2
C v18 regex help please Support 1
C Font of RegEx Analyzer Support 0
D Regex problem Support 17
mikea How to? Regex match when there shouldn't be (?) Support 18
JohnQSmith Fixed Copying with regex (several issues) Support 7
D Help needed to get a regex to work Support 3
thedave WAD Regex match on \h Support 5
Ville Regex & conditionals Support 9
samintz Regex Rename Support 2
vefatica @REGEX revisited Support 4
vefatica @REGEX question Support 6
vefatica Regex question Support 5
B Regex and Replace Support 6
Stefano Piccardi detecting BOM, FFIND multibyte regex Support 18
dcantor FFIND syntax -- is /E"regex" /X supported? Support 2
P Renaming files with regex. Support 6
B "Fun" with DO and Regex Support 12
P Need to use a regex in a "for" loop. Support 54
H @XMLNODES - New behavior? Support 3
Jesse Heines Strange Line Wrapping Behavior Support 14
H Behavior change re piping a string to a Java program Support 1
Jay Sage Baffling Behavior With TPIPE Support 5
D Pasting Unicode data has different behavior on TCC and CMD Support 2
P "Set" command behavior - a bug? Support 3
P LOG command behavior Support 3
I Puzzling Behavior of TDRV and DEL Support 2
N Fixed Strange dir behavior Support 6
A Inconsistent @WINPOS // ACTIVATE /POS= behavior Support 0
P Strange mouse behavior with list Support 2
R Find in screen buffer - find next behavior Support 0
D v20 code page behavior changes Support 2
D Strange DO behavior with /O Support 5
Jay Sage Change in Behavior of Activate Command Support 4
deleyd Fixed Behavior different than CMD Support 1
jwiede Difference in "FOR /F" behavior (?) Support 1
R Difference in behavior of RMDIR vs. CMD.EXE? Support 5
D Fixed Change in behavior of variable expansion between 16 and 17 Support 3
D Unexpected behavior Support 8

Similar threads