Regex pattern to validate Linux folder path The Next CEO of Stack OverflowIs there a way in Java to determine if a path is valid without attempting to create a file?What is the most correct regular expression for a UNIX file path?what is path //, how is it different from /Regular expression to validate windows and linux path with extensionValidate decimal numbers in JavaScript - IsNumeric()How to validate an email address in JavaScript?A comprehensive regex for phone number validationHow to validate an email address using a regular expression?Shell command to tar directory excluding certain files/foldersHow to symlink a file in Linux?How do I change permissions for a folder and all of its subfolders and files in one step in Linux?How do I copy folder with files to another folder in Unix/Linux?How do I find all files containing specific text on Linux?Why does array[idx++]+=“a” increase idx once in Java 8 but twice in Java 9 and 10?

Why does the freezing point matter when picking cooler ice packs?

How should I connect my cat5 cable to connectors having an orange-green line?

Does Germany produce more waste than the US?

Are British MPs missing the point, with these 'Indicative Votes'?

Is this a new Fibonacci Identity?

Why was Sir Cadogan fired?

Finitely generated matrix groups whose eigenvalues are all algebraic

How to show a landlord what we have in savings?

Why does sin(x) - sin(y) equal this?

pgfplots: How to draw a tangent graph below two others?

Read/write a pipe-delimited file line by line with some simple text manipulation

Can I hook these wires up to find the connection to a dead outlet?

Find the majority element, which appears more than half the time

Strange use of "whether ... than ..." in official text

Is there a rule of thumb for determining the amount one should accept for a settlement offer?

Is it a bad idea to plug the other end of ESD strap to wall ground?

Upgrading From a 9 Speed Sora Derailleur?

What did the word "leisure" mean in late 18th Century usage?

Calculating discount not working

How did scripture get the name bible?

Oldie but Goldie

Why do we say “un seul M” and not “une seule M” even though M is a “consonne”?

That's an odd coin - I wonder why

How can the PCs determine if an item is a phylactery?



Regex pattern to validate Linux folder path



The Next CEO of Stack OverflowIs there a way in Java to determine if a path is valid without attempting to create a file?What is the most correct regular expression for a UNIX file path?what is path //, how is it different from /Regular expression to validate windows and linux path with extensionValidate decimal numbers in JavaScript - IsNumeric()How to validate an email address in JavaScript?A comprehensive regex for phone number validationHow to validate an email address using a regular expression?Shell command to tar directory excluding certain files/foldersHow to symlink a file in Linux?How do I change permissions for a folder and all of its subfolders and files in one step in Linux?How do I copy folder with files to another folder in Unix/Linux?How do I find all files containing specific text on Linux?Why does array[idx++]+=“a” increase idx once in Java 8 but twice in Java 9 and 10?










0















Using JAVA.
I am trying to find a more elegant way for validating a Linux folder path (not including the file name).



What I have so far is this: "^\/$|^((\/([a-zA-Z0-9_-]+))+)$"



Folder paths should include only following characters: letters, numbers, dashes or underscore.



Test cases



Valid/ matches:



  • /

  • /abc

  • /abc/abc/abc/abc

Invalid / not-matches:




  • null or empty string

  • /abc/

  • /abc/abc/abc/abc/









share|improve this question
























  • Well the elegant way would be to not use regex at all and instead use the nio libraries to determine if the path is valid....

    – Roddy of the Frozen Peas
    Mar 8 at 20:14











  • What is the use-case for your validation? Why is your RegEx not working for you? Maybe we can find a better solution besides using the RegEx :)

    – hc_dev
    Mar 8 at 21:15











  • My pattern works, it just looks clunky, and wasn't sure I was doing it right.

    – afrey
    Mar 8 at 21:26











  • Why are you limiting the folder names to alphanumeric? A folder name can contain close to any character.

    – Toto
    Mar 9 at 10:28











  • Using only alphanumeric because of requirements in the application we are using.

    – afrey
    Mar 10 at 13:07















0















Using JAVA.
I am trying to find a more elegant way for validating a Linux folder path (not including the file name).



What I have so far is this: "^\/$|^((\/([a-zA-Z0-9_-]+))+)$"



Folder paths should include only following characters: letters, numbers, dashes or underscore.



Test cases



Valid/ matches:



  • /

  • /abc

  • /abc/abc/abc/abc

Invalid / not-matches:




  • null or empty string

  • /abc/

  • /abc/abc/abc/abc/









share|improve this question
























  • Well the elegant way would be to not use regex at all and instead use the nio libraries to determine if the path is valid....

    – Roddy of the Frozen Peas
    Mar 8 at 20:14











  • What is the use-case for your validation? Why is your RegEx not working for you? Maybe we can find a better solution besides using the RegEx :)

    – hc_dev
    Mar 8 at 21:15











  • My pattern works, it just looks clunky, and wasn't sure I was doing it right.

    – afrey
    Mar 8 at 21:26











  • Why are you limiting the folder names to alphanumeric? A folder name can contain close to any character.

    – Toto
    Mar 9 at 10:28











  • Using only alphanumeric because of requirements in the application we are using.

    – afrey
    Mar 10 at 13:07













0












0








0








Using JAVA.
I am trying to find a more elegant way for validating a Linux folder path (not including the file name).



What I have so far is this: "^\/$|^((\/([a-zA-Z0-9_-]+))+)$"



Folder paths should include only following characters: letters, numbers, dashes or underscore.



Test cases



Valid/ matches:



  • /

  • /abc

  • /abc/abc/abc/abc

Invalid / not-matches:




  • null or empty string

  • /abc/

  • /abc/abc/abc/abc/









share|improve this question
















Using JAVA.
I am trying to find a more elegant way for validating a Linux folder path (not including the file name).



What I have so far is this: "^\/$|^((\/([a-zA-Z0-9_-]+))+)$"



Folder paths should include only following characters: letters, numbers, dashes or underscore.



Test cases



Valid/ matches:



  • /

  • /abc

  • /abc/abc/abc/abc

Invalid / not-matches:




  • null or empty string

  • /abc/

  • /abc/abc/abc/abc/






java regex linux validation filepath






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 21:31









hc_dev

550514




550514










asked Mar 8 at 19:19









afreyafrey

186




186












  • Well the elegant way would be to not use regex at all and instead use the nio libraries to determine if the path is valid....

    – Roddy of the Frozen Peas
    Mar 8 at 20:14











  • What is the use-case for your validation? Why is your RegEx not working for you? Maybe we can find a better solution besides using the RegEx :)

    – hc_dev
    Mar 8 at 21:15











  • My pattern works, it just looks clunky, and wasn't sure I was doing it right.

    – afrey
    Mar 8 at 21:26











  • Why are you limiting the folder names to alphanumeric? A folder name can contain close to any character.

    – Toto
    Mar 9 at 10:28











  • Using only alphanumeric because of requirements in the application we are using.

    – afrey
    Mar 10 at 13:07

















  • Well the elegant way would be to not use regex at all and instead use the nio libraries to determine if the path is valid....

    – Roddy of the Frozen Peas
    Mar 8 at 20:14











  • What is the use-case for your validation? Why is your RegEx not working for you? Maybe we can find a better solution besides using the RegEx :)

    – hc_dev
    Mar 8 at 21:15











  • My pattern works, it just looks clunky, and wasn't sure I was doing it right.

    – afrey
    Mar 8 at 21:26











  • Why are you limiting the folder names to alphanumeric? A folder name can contain close to any character.

    – Toto
    Mar 9 at 10:28











  • Using only alphanumeric because of requirements in the application we are using.

    – afrey
    Mar 10 at 13:07
















Well the elegant way would be to not use regex at all and instead use the nio libraries to determine if the path is valid....

– Roddy of the Frozen Peas
Mar 8 at 20:14





Well the elegant way would be to not use regex at all and instead use the nio libraries to determine if the path is valid....

– Roddy of the Frozen Peas
Mar 8 at 20:14













What is the use-case for your validation? Why is your RegEx not working for you? Maybe we can find a better solution besides using the RegEx :)

– hc_dev
Mar 8 at 21:15





What is the use-case for your validation? Why is your RegEx not working for you? Maybe we can find a better solution besides using the RegEx :)

– hc_dev
Mar 8 at 21:15













My pattern works, it just looks clunky, and wasn't sure I was doing it right.

– afrey
Mar 8 at 21:26





My pattern works, it just looks clunky, and wasn't sure I was doing it right.

– afrey
Mar 8 at 21:26













Why are you limiting the folder names to alphanumeric? A folder name can contain close to any character.

– Toto
Mar 9 at 10:28





Why are you limiting the folder names to alphanumeric? A folder name can contain close to any character.

– Toto
Mar 9 at 10:28













Using only alphanumeric because of requirements in the application we are using.

– afrey
Mar 10 at 13:07





Using only alphanumeric because of requirements in the application we are using.

– afrey
Mar 10 at 13:07












3 Answers
3






active

oldest

votes


















0














Issue with your RegEx



Your supplied RegEx is working on the test-cases.



You could even reduce it by removing backslashes \ and outer pair of parentheses. Begin ^ and end $ are only needed once (around the two alternatives).



Possible Solution using Regular Expression



You can test the RegEx on RegexPlanet.com (click on Java-Button for tests)



^/|(/[a-zA-Z0-9_-]+)+$


or equivalent (see demo on RegexPlanet)



^/|(/[w-]+)+$


Explained:
w matches a word-character (same as [a-zA-Z0-9_], not matching the dash).



Implementation in Java code:



public boolean isValidLinuxDirectory(String path) (/[a-zA-Z0-9_-]+)+$");
return path != null && !path.trim().isEmpty() && linuxDirectoryPattern.matcher( path ).matches();



Alternative Solution using File



Note the docs on isDirectory():




Returns:
true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise




So it may only validate your requirements (valid Linux folder) if run on a Linux machine and if the folder/directory exists.



public boolean isValidExistingDirectory(String path) 
if (path == null


Extended Solution



As stated in comment the special form of root // should also be valid. Then use this RegEx:



^/|//|(/[w-]+)+$


It supports:



  1. root-directory /

  2. special form of root-directory //

  3. any non-root directory, which name is composed out of alphas, numbers, dash or underscore (e.g. /abc/123/_abc-123)

See also



  • What is the most correct regular expression for a UNIX file path?

  • Regular expression to validate windows and linux path with extension

  • what is path //, how is it different from /





share|improve this answer

























  • Thanks a bunch! Very helpful!

    – afrey
    Mar 10 at 13:05











  • ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

    – afrey
    Mar 10 at 14:43












  • @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

    – hc_dev
    Mar 11 at 11:10


















0














To cover all cases including the root directory, you will need the following:



^/$|(/[a-zA-Z_0-9-]+)+$


See Regex Demo using global and multiline modifiers.






share|improve this answer
































    0














    Here ya go:
    /[a-zA-Z0-9_/-]*[^/]$



    EDIT



    First character matches a forward slash /. The following character group matches a-z, A-Z, 0-9, underscores, forward slashes, and dashes (all accepted directory and filename characters). The following asterisk makes the pattern match that character group 0 or more times (so any combo of those characters). The last character group has a negation ^ meaning it matches anything EXCEPT what's in the character group, being the final forward slash that we don't want to match. Finally the $ to end the string.






    share|improve this answer

























    • Also if you can actually use the filesystem take a look at this

      – Logan Rodie
      Mar 8 at 19:47






    • 2





      Could you explain how that works?

      – Wai Ha Lee
      Mar 9 at 1:06











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069650%2fregex-pattern-to-validate-linux-folder-path%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Issue with your RegEx



    Your supplied RegEx is working on the test-cases.



    You could even reduce it by removing backslashes \ and outer pair of parentheses. Begin ^ and end $ are only needed once (around the two alternatives).



    Possible Solution using Regular Expression



    You can test the RegEx on RegexPlanet.com (click on Java-Button for tests)



    ^/|(/[a-zA-Z0-9_-]+)+$


    or equivalent (see demo on RegexPlanet)



    ^/|(/[w-]+)+$


    Explained:
    w matches a word-character (same as [a-zA-Z0-9_], not matching the dash).



    Implementation in Java code:



    public boolean isValidLinuxDirectory(String path) (/[a-zA-Z0-9_-]+)+$");
    return path != null && !path.trim().isEmpty() && linuxDirectoryPattern.matcher( path ).matches();



    Alternative Solution using File



    Note the docs on isDirectory():




    Returns:
    true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise




    So it may only validate your requirements (valid Linux folder) if run on a Linux machine and if the folder/directory exists.



    public boolean isValidExistingDirectory(String path) 
    if (path == null


    Extended Solution



    As stated in comment the special form of root // should also be valid. Then use this RegEx:



    ^/|//|(/[w-]+)+$


    It supports:



    1. root-directory /

    2. special form of root-directory //

    3. any non-root directory, which name is composed out of alphas, numbers, dash or underscore (e.g. /abc/123/_abc-123)

    See also



    • What is the most correct regular expression for a UNIX file path?

    • Regular expression to validate windows and linux path with extension

    • what is path //, how is it different from /





    share|improve this answer

























    • Thanks a bunch! Very helpful!

      – afrey
      Mar 10 at 13:05











    • ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

      – afrey
      Mar 10 at 14:43












    • @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

      – hc_dev
      Mar 11 at 11:10















    0














    Issue with your RegEx



    Your supplied RegEx is working on the test-cases.



    You could even reduce it by removing backslashes \ and outer pair of parentheses. Begin ^ and end $ are only needed once (around the two alternatives).



    Possible Solution using Regular Expression



    You can test the RegEx on RegexPlanet.com (click on Java-Button for tests)



    ^/|(/[a-zA-Z0-9_-]+)+$


    or equivalent (see demo on RegexPlanet)



    ^/|(/[w-]+)+$


    Explained:
    w matches a word-character (same as [a-zA-Z0-9_], not matching the dash).



    Implementation in Java code:



    public boolean isValidLinuxDirectory(String path) (/[a-zA-Z0-9_-]+)+$");
    return path != null && !path.trim().isEmpty() && linuxDirectoryPattern.matcher( path ).matches();



    Alternative Solution using File



    Note the docs on isDirectory():




    Returns:
    true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise




    So it may only validate your requirements (valid Linux folder) if run on a Linux machine and if the folder/directory exists.



    public boolean isValidExistingDirectory(String path) 
    if (path == null


    Extended Solution



    As stated in comment the special form of root // should also be valid. Then use this RegEx:



    ^/|//|(/[w-]+)+$


    It supports:



    1. root-directory /

    2. special form of root-directory //

    3. any non-root directory, which name is composed out of alphas, numbers, dash or underscore (e.g. /abc/123/_abc-123)

    See also



    • What is the most correct regular expression for a UNIX file path?

    • Regular expression to validate windows and linux path with extension

    • what is path //, how is it different from /





    share|improve this answer

























    • Thanks a bunch! Very helpful!

      – afrey
      Mar 10 at 13:05











    • ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

      – afrey
      Mar 10 at 14:43












    • @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

      – hc_dev
      Mar 11 at 11:10













    0












    0








    0







    Issue with your RegEx



    Your supplied RegEx is working on the test-cases.



    You could even reduce it by removing backslashes \ and outer pair of parentheses. Begin ^ and end $ are only needed once (around the two alternatives).



    Possible Solution using Regular Expression



    You can test the RegEx on RegexPlanet.com (click on Java-Button for tests)



    ^/|(/[a-zA-Z0-9_-]+)+$


    or equivalent (see demo on RegexPlanet)



    ^/|(/[w-]+)+$


    Explained:
    w matches a word-character (same as [a-zA-Z0-9_], not matching the dash).



    Implementation in Java code:



    public boolean isValidLinuxDirectory(String path) (/[a-zA-Z0-9_-]+)+$");
    return path != null && !path.trim().isEmpty() && linuxDirectoryPattern.matcher( path ).matches();



    Alternative Solution using File



    Note the docs on isDirectory():




    Returns:
    true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise




    So it may only validate your requirements (valid Linux folder) if run on a Linux machine and if the folder/directory exists.



    public boolean isValidExistingDirectory(String path) 
    if (path == null


    Extended Solution



    As stated in comment the special form of root // should also be valid. Then use this RegEx:



    ^/|//|(/[w-]+)+$


    It supports:



    1. root-directory /

    2. special form of root-directory //

    3. any non-root directory, which name is composed out of alphas, numbers, dash or underscore (e.g. /abc/123/_abc-123)

    See also



    • What is the most correct regular expression for a UNIX file path?

    • Regular expression to validate windows and linux path with extension

    • what is path //, how is it different from /





    share|improve this answer















    Issue with your RegEx



    Your supplied RegEx is working on the test-cases.



    You could even reduce it by removing backslashes \ and outer pair of parentheses. Begin ^ and end $ are only needed once (around the two alternatives).



    Possible Solution using Regular Expression



    You can test the RegEx on RegexPlanet.com (click on Java-Button for tests)



    ^/|(/[a-zA-Z0-9_-]+)+$


    or equivalent (see demo on RegexPlanet)



    ^/|(/[w-]+)+$


    Explained:
    w matches a word-character (same as [a-zA-Z0-9_], not matching the dash).



    Implementation in Java code:



    public boolean isValidLinuxDirectory(String path) (/[a-zA-Z0-9_-]+)+$");
    return path != null && !path.trim().isEmpty() && linuxDirectoryPattern.matcher( path ).matches();



    Alternative Solution using File



    Note the docs on isDirectory():




    Returns:
    true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise




    So it may only validate your requirements (valid Linux folder) if run on a Linux machine and if the folder/directory exists.



    public boolean isValidExistingDirectory(String path) 
    if (path == null


    Extended Solution



    As stated in comment the special form of root // should also be valid. Then use this RegEx:



    ^/|//|(/[w-]+)+$


    It supports:



    1. root-directory /

    2. special form of root-directory //

    3. any non-root directory, which name is composed out of alphas, numbers, dash or underscore (e.g. /abc/123/_abc-123)

    See also



    • What is the most correct regular expression for a UNIX file path?

    • Regular expression to validate windows and linux path with extension

    • what is path //, how is it different from /






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 11 at 11:03

























    answered Mar 8 at 20:03









    hc_devhc_dev

    550514




    550514












    • Thanks a bunch! Very helpful!

      – afrey
      Mar 10 at 13:05











    • ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

      – afrey
      Mar 10 at 14:43












    • @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

      – hc_dev
      Mar 11 at 11:10

















    • Thanks a bunch! Very helpful!

      – afrey
      Mar 10 at 13:05











    • ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

      – afrey
      Mar 10 at 14:43












    • @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

      – hc_dev
      Mar 11 at 11:10
















    Thanks a bunch! Very helpful!

    – afrey
    Mar 10 at 13:05





    Thanks a bunch! Very helpful!

    – afrey
    Mar 10 at 13:05













    ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

    – afrey
    Mar 10 at 14:43






    ^/|/[a-zA-Z0-9_-]+)+$ does not work for the case where the folder path is //. ^/$|^(/[a-zA-Z0-9_-]+)+$ works.

    – afrey
    Mar 10 at 14:43














    @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

    – hc_dev
    Mar 11 at 11:10





    @afrey OK. Then please UPDATE your question for extended requirement (as I just did). Sure that your regex ^/$|^(/[a-zA-Z0-9_-]+)+$ does match the special-root (//) ??

    – hc_dev
    Mar 11 at 11:10













    0














    To cover all cases including the root directory, you will need the following:



    ^/$|(/[a-zA-Z_0-9-]+)+$


    See Regex Demo using global and multiline modifiers.






    share|improve this answer





























      0














      To cover all cases including the root directory, you will need the following:



      ^/$|(/[a-zA-Z_0-9-]+)+$


      See Regex Demo using global and multiline modifiers.






      share|improve this answer



























        0












        0








        0







        To cover all cases including the root directory, you will need the following:



        ^/$|(/[a-zA-Z_0-9-]+)+$


        See Regex Demo using global and multiline modifiers.






        share|improve this answer















        To cover all cases including the root directory, you will need the following:



        ^/$|(/[a-zA-Z_0-9-]+)+$


        See Regex Demo using global and multiline modifiers.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 8 at 20:29

























        answered Mar 8 at 20:11









        AdminOfThingsAdminOfThings

        1,6471212




        1,6471212





















            0














            Here ya go:
            /[a-zA-Z0-9_/-]*[^/]$



            EDIT



            First character matches a forward slash /. The following character group matches a-z, A-Z, 0-9, underscores, forward slashes, and dashes (all accepted directory and filename characters). The following asterisk makes the pattern match that character group 0 or more times (so any combo of those characters). The last character group has a negation ^ meaning it matches anything EXCEPT what's in the character group, being the final forward slash that we don't want to match. Finally the $ to end the string.






            share|improve this answer

























            • Also if you can actually use the filesystem take a look at this

              – Logan Rodie
              Mar 8 at 19:47






            • 2





              Could you explain how that works?

              – Wai Ha Lee
              Mar 9 at 1:06















            0














            Here ya go:
            /[a-zA-Z0-9_/-]*[^/]$



            EDIT



            First character matches a forward slash /. The following character group matches a-z, A-Z, 0-9, underscores, forward slashes, and dashes (all accepted directory and filename characters). The following asterisk makes the pattern match that character group 0 or more times (so any combo of those characters). The last character group has a negation ^ meaning it matches anything EXCEPT what's in the character group, being the final forward slash that we don't want to match. Finally the $ to end the string.






            share|improve this answer

























            • Also if you can actually use the filesystem take a look at this

              – Logan Rodie
              Mar 8 at 19:47






            • 2





              Could you explain how that works?

              – Wai Ha Lee
              Mar 9 at 1:06













            0












            0








            0







            Here ya go:
            /[a-zA-Z0-9_/-]*[^/]$



            EDIT



            First character matches a forward slash /. The following character group matches a-z, A-Z, 0-9, underscores, forward slashes, and dashes (all accepted directory and filename characters). The following asterisk makes the pattern match that character group 0 or more times (so any combo of those characters). The last character group has a negation ^ meaning it matches anything EXCEPT what's in the character group, being the final forward slash that we don't want to match. Finally the $ to end the string.






            share|improve this answer















            Here ya go:
            /[a-zA-Z0-9_/-]*[^/]$



            EDIT



            First character matches a forward slash /. The following character group matches a-z, A-Z, 0-9, underscores, forward slashes, and dashes (all accepted directory and filename characters). The following asterisk makes the pattern match that character group 0 or more times (so any combo of those characters). The last character group has a negation ^ meaning it matches anything EXCEPT what's in the character group, being the final forward slash that we don't want to match. Finally the $ to end the string.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 11 at 15:37

























            answered Mar 8 at 19:45









            Logan RodieLogan Rodie

            492310




            492310












            • Also if you can actually use the filesystem take a look at this

              – Logan Rodie
              Mar 8 at 19:47






            • 2





              Could you explain how that works?

              – Wai Ha Lee
              Mar 9 at 1:06

















            • Also if you can actually use the filesystem take a look at this

              – Logan Rodie
              Mar 8 at 19:47






            • 2





              Could you explain how that works?

              – Wai Ha Lee
              Mar 9 at 1:06
















            Also if you can actually use the filesystem take a look at this

            – Logan Rodie
            Mar 8 at 19:47





            Also if you can actually use the filesystem take a look at this

            – Logan Rodie
            Mar 8 at 19:47




            2




            2





            Could you explain how that works?

            – Wai Ha Lee
            Mar 9 at 1:06





            Could you explain how that works?

            – Wai Ha Lee
            Mar 9 at 1:06

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069650%2fregex-pattern-to-validate-linux-folder-path%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme