%@regex["^-","-a"] returns 0, "^-" =~ "-a" is false (no match)

May 20, 2017
22
0
Let's see if the string "-a" looks like an option, that is, whether it begins with a hyphen:
Code:
echo %@regex["^-","-a"]
0
How odd. Maybe it must match the full string, even though that would make @regexindex[] meaningless:
Code:
echo %@regex["^-.*$","-a"]
0
Even weirder. Let me try that in in a Python script … works. Perl … works. gawk … works. Hmm. Let's try TCC again, but instead of the Ruby flavour we'll try TCC's perl, grep, gnu, and Python flavours … Nope. OK, back to Ruby flavour, just for consistency.
Code:
echo %@regex["-","-a"]
1
Well, something works, at least. Regrettably (and expectedly), however, I wanted an anchored search, and this now also matches:
Code:
echo %@regex["-","x-a"]
1
Let's give this one last try:
Code:
echo %@regex["\A-","-a"]
0
Nope. At least the starting anchors dislike me.
What am I doing wrong, please?

Thanks,
Felix.
 
It works without the quotes: echo %@regex[^-,-a]
The documentation says the quotes are needed when there is a space in the expression.
Maybe there is something confusing here because the caret is also an escape character for TCC.
 
May 20, 2008
11,431
99
Syracuse, NY, USA
Apparently the quotes are preserved in the second parameter.

Code:
v:\> echo %@regex["^-",-a]
1

v:\> echo %@regex["^^"","a]
1

v:\> echo %@regex["^a","a]
0
 
May 20, 2008
11,431
99
Syracuse, NY, USA
It works without the quotes: echo %@regex[^-,-a]
The documentation says the quotes are needed when there is a space in the expression.
Maybe there is something confusing here because the caret is also an escape character for TCC.
It didn't realy work. Without the quotes on the first parameter, the '^' got lost.

Code:
v:\> echo %@regex[^-,a-a]
1
 
May 20, 2017
22
0
Christian,
Vincent,

thanks a million! I can make sure the second string always will be quoted and then add the intial quote to the regex, or just make that initial quote an optional match.

Thanks!!

Felix.
 
Similar threads
Thread starter Title Forum Replies Date
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: behavior vs. documentation 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
Peter Murschall %_BATTERY returns 0 and others Support 9
W pdir returns diff results between tcc and tcmd - one is an error msg Support 5
M Fixed PSHELL command returns error Support 2
H Fixed DIR /G returns wrong sizes Support 2
D COPY returns ERRORLEVEL 2 Support 5
Steve Pitts WAD @MD5 returns incorrect results for strings Support 2
G WAD _DOS and VER/r returns incorect value Support 2
R Function #IDOW returns only 2 characters Support 10
D @IPADDRESS[] always returns 11001 Support 8
vefatica Fixed @FILEOPEN returns 4294967295 Support 2
I Possible Bug: History /n Returns Nothing Support 3
S WAD _exit returns invalid code under some conditions Support 13
M %_ADMIN always returns 0 Support 3
B Bdebugger doesn't recognize breakpoint after batch file returns Support 2
N Delay returns immediately Support 20
B %ProgramFiles(x86)% returns different values in TCC and CMD Support 3
J BUG: MSGBOX after DETACH returns early with 0 on Win7 Support 3
A Clam AV False Positives Support 0
fpefpe How to? False Positive Support 3
vefatica TCC: Unknown command "False" Support 4

Similar threads