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?
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
add a comment |
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
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
add a comment |
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
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
java regex linux validation filepath
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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:
- root-directory
/
- special form of root-directory
//
- 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 /
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
add a comment |
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.
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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:
- root-directory
/
- special form of root-directory
//
- 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 /
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
add a comment |
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:
- root-directory
/
- special form of root-directory
//
- 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 /
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
add a comment |
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:
- root-directory
/
- special form of root-directory
//
- 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 /
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:
- root-directory
/
- special form of root-directory
//
- 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 /
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Mar 8 at 20:29
answered Mar 8 at 20:11
AdminOfThingsAdminOfThings
1,6471212
1,6471212
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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