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

Regular expressions in FOR's set?

Discussion in 'Support' started by vefatica, Oct 29, 2009.

  1. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,783
    Likes Received:
    29
    I guess I/m using regular expressions here ... right?

    Code:
    v:\> for %f in ( "::.*\..x." ) echo %f
    V:\10.txt
    V:\100.txt
    V:\a b.txt
    V:\ab.txt
    V:\abc.txt
    V:\alphabet.txt
    V:\anagram.exe
    V:\avetemp.txt
    (snip)
    If so, why doesn't the following find any files (or, it seems, even look for them)?

    Code:
    v:\> for %f in ( "::..\..x." ) echo %f
    "::..\..x."
    I'd expect it to find filenames (of which there are plenty) with at least two characters before a "." followed by at least three characters, the second of which is "x".
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,726
    Likes Received:
    80
    WAD - FOR only looks for matching filenames if you include wildcards, and
    you don't have any. So FOR assumes you want to substitute a text string.

    (And no, I cannot assume that a "::" is equivalent to a wildcard, as it
    would break CMD compatibility. Use DO instead.)
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,783
    Likes Received:
    29
    On Thu, 29 Oct 2009 22:13:17 -0500, rconn <> wrote:

    |---Quote---
    |> If so, why doesn't the following find any files (or, it seems, even
    |> look for them)?
    |>
    |> Code:
    |> ---------
    |> v:\> for %f in ( "::..\..x." ) echo %f
    |> "::..\..x."
    |> ---------
    |> I'd expect it to find filenames (of which there are plenty) with at
    |> least two characters before a "." followed by at least three
    |> characters, the second of which is "x".
    |---End Quote---
    |WAD - FOR only looks for matching filenames if you include wildcards, and
    |you don't have any. So FOR assumes you want to substitute a text string.
    |
    |(And no, I cannot assume that a "::" is equivalent to a wildcard, as it
    |would break CMD compatibility. Use DO instead.)

    What CMD compatibility?

    I think of "::" as meaning "what follows is a regex". DIR gets it right with
    the exact same spec ("::..\..x.").

    I can't use DO on the command line.
    --
    - Vince
     
  4. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    So, if I understand correctly ... you could tack a useless .* ("zero or more of anything") on the end of the regex, and FOR would see it as a wildcard expression?

    Code:
    for %f in ( "::..\..x..*" ) echo %f
    
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,783
    Likes Received:
    29
    On Thu, 29 Oct 2009 22:55:31 -0500, Charles Dye <> wrote:

    |So, if I understand correctly ... you could tack a useless .* ("zero or more of anything") on the end of the regex, and FOR would see it as a wildcard expression?
    |
    |
    |Code:
    |---------
    |for %f in ( "::..\..x..*" ) echo %f
    |---------

    As kludges go, that's not too bad. But it's still a kludge. IMHO, "::" should
    be a tip-off that the following is a regex and thus a file spec (since I can't
    think of another reason to put a regex in FOR's set).
    --
    - Vince
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,726
    Likes Received:
    80
    That's correct.


    Not going to happen -- I've seen a number of .CMD files where the FOR set is
    a string set containing (or even starting with) ::, and they're definitely
    NOT intended to be regular expressions.

    As I've mentioned a few dozen times in the past, FOR is very strictly
    limited in terms of possible enhancements due to CMD compatibility concerns.
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,523
    Likes Received:
    4
    rconn wrote:
    | As I've mentioned a few dozen times in the past, FOR is very strictly
    | limited in terms of possible enhancements due to CMD compatibility
    | concerns.

    Since DO is not usable from the command prompt, FOR is our only option for
    "once-only" tasks, short of Vince's new CDO idea. How about a new command,
    REPEAT, which would be essentially a duplicate of FOR, but without the CMD
    compatibility baggage? It could share most of its code with FOR, and only
    deviate when one of the compatibility issues comes into play.
    --
    Steve
     
  8. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,277
    Likes Received:
    38
    Or perhaps a /W option for FOR, to indicate that all the sets inside the parentheses are to be treated as wildspecs?
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,783
    Likes Received:
    29
    On Fri, 30 Oct 2009 07:22:09 -0500, rconn <> wrote:

    |As I've mentioned a few dozen times in the past, FOR is very strictly
    |limited in terms of possible enhancements due to CMD compatibility concerns.

    I appreciate that (and keep forgetting it). But it has been that way for a long
    time and 4NT/TCC has ... well ... remained compatible. CMD needs to be
    one-upped!

    --
    - Vince
     
  10. thedave

    Joined:
    Nov 13, 2008
    Messages:
    254
    Likes Received:
    2
    On Fri, 30 Oct 2009 07:21:57 -0500, rconn <> was
    claimed to have wrote:


    This might be a stupid question, but is there an alternative that works
    from the command line and is nearly as flexible?

    It occurs to me that maybe a better long term solution would be some
    sort of FOR eXtension (similar to PDIR), that would be designed without
    concern for CMD compatibility, while still maintaining simple looping
    capabilities without leaving the command line.
     
  11. thedave

    Joined:
    Nov 13, 2008
    Messages:
    254
    Likes Received:
    2
    On Fri, 30 Oct 2009 09:17:07 -0500, Charles Dye <>
    was claimed to have wrote:


    This is the best idea I've heard yet.
     

Share This Page