%@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
12,165
133
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
12,165
133
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