Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    More RegEx validating stuff

    Hello, everyone.

    I'm going to be heading home, shortly, so won't respond until tomorrow morning; but I could use some help with a RegEx test mask.

    Basically, I'm trying to validate for both Windows and *nix paths.

    Good is:
    [drive letter]:\folder1\folder2\folder_3\folder-4
    \\server\share\folder_1\folder-2
    //usr/folder_1/folder-2

    Bad could be
    [anything other than drive letter or "\\"]folder\\folder_1\/
    \\\server\\folder\\folder_2
    ///?%$\folder/folder_2//bad_path

    Here is what I have, so far. I'm getting most of the validation I want from it, but I just can't seem to get past the last few details.
    Code:
    /^(([a-z]\:\\|\\{2})[\w\d\\\.\_\-]+|\/[^\/{2,}][\w\d\/\.\_\-]+)$/
    red = windows, blue = *nix
    Thank you,
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    \w\d ??

    \w is the same as [a-zA-Z0-9_]
    \d is the same as [0-9]

    Redundant.

    [\w\\\.\-]+

    Would be sufficnent.

    But many other characters are legal in folder names, certainly in windows. Space, %, $, and several others.

    Here:
    Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:

    The following reserved characters:
    < (less than)
    > (greater than)
    : (colon)
    " (double quote)
    / (forward slash)
    \ (backslash)
    | (vertical bar or pipe)
    ? (question mark)
    * (asterisk)
    Integer value zero, sometimes referred to as the ASCII NUL character.
    Characters whose integer representations are in the range from 1 through 31 [with some exceptionsl]
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    And this makes no sense:

    [^\/{2,}]

    When you use [^...] that means "allow ANY character except those listed". And by and large, you don't need to excape characters after the ^.

    So your expression is saying "any characters except / and { and 2 and , and }"

    Which surely isn't what you meant.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I use RegEx so rarely, every time I start to learn it I get done what needs doing and then there's no need for it and I focus on other things. So despite my years of developing, I am still not completely familiar with all the rules and such.

    I'm tweaking and tweaking, playing with it. Once I get what I need, I'll post the solution.

    Thanks,
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •