1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help needed to get a regex to work

Discussion in 'Support' started by djspits, Feb 15, 2013.

  1. djspits

    Joined:
    Apr 13, 2010
    Messages:
    187
    Likes Received:
    2
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    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
     
  4. djspits

    Joined:
    Apr 13, 2010
    Messages:
    187
    Likes Received:
    2
    Thx Vince, for getting me un-stuck.
    Cheers,
    DJ.
     

Share This Page