Help needed to get a regex to work

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Apr 13, 2010
190
2
57
The Hague
#1
From:
"(C)ontinue, (Q)uit current batch only or (A)bort all batch processing?"​

using perl syntax regex
\((\w{1})\)​

I want to extract "CQA"

echo %@REGEXSUB[%n,\((\w{1})\),"(C)ontinue (Q)uit current batch only or (A)bort all batch processing?"]​

shows "C" for n=1, but no results for higher values.

I'm lost.

Suggestions?

Cheers,
DJ
 
#2
I'm not sure what is the intended behavior, and, depending on what it actually is, the help may be misleading. One interpretation is that the index (n) specifies which of your parenthesized expressions you want returned (and you specified only one parenthesized expression). This example would seem to indicate that:
Code:
v:\> echo %@REGEXSUB[1,\((.)\).*\((.)\),"(C) (Q) (A)"]
C
 
v:\> echo %@REGEXSUB[2,\((.)\).*\((.)\).*\((.)\),"(C) (Q) (A)"]
Q
 
v:\> echo %@REGEXSUB[3,\((.)\).*\((.)\).*\((.)\),"(C) (Q) (A)"]
A
I don't think TCC has anything built-in that will extract all three. If you use my 4UTILS plugin, perhaps @XREPLACE will help.
Code:
v:\> echo %@xreplace[.*\((.)\).*\((.)\).*\((.)\).*,\1\2\3,"(C)ont (Q)uit (A)bort"]
CQA
 
#3
I misspoke. TCC has, built-in, @REREPLACE which works much like @XREPLACE.
Code:
v:\> echo %@rereplace[.*\((.)\).*\((.)\).*\((.)\).*,\1\2\3,"(C)ont (Q)uit (A)bort"]
CQA