File Path (Unix) Regex Pattern
Matches absolute Unix/Linux file paths starting with forward slash. Validates path component characters.
Live Regex Tester
Pattern Breakdown
Code Examples
JavaScript
const regex = /^\/(?:[a-zA-Z0-9._-]+\/?)*$/; const test = "/usr/local/bin/node"; console.log(regex.test(test)); // true // Extract matches const matches = test.match(regex); console.log(matches);
Python
import re pattern = r'^\/(?:[a-zA-Z0-9._-]+\/?)*$' test = "/usr/local/bin/node" match = re.search(pattern, test) print(match) # Found!
Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^\/(?:[a-zA-Z0-9._-]+\/?)*$`)
fmt.Println(re.MatchString("/usr/local/bin/node")) // true
}Common Use Cases
Match Examples
| Input | Result |
|---|---|
| /usr/local/bin/node | Match |
| C:\Windows | No Match |
About the File Path (Unix) Regex
Matches absolute Unix/Linux file paths starting with forward slash. Validates path component characters.
Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The file path (unix) pattern is classified as beginner difficulty in the data formats category. It works in all major programming languages.
When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.
More Data Formats Patterns
Need More Regex Patterns?
Browse our complete library of 100+ regex patterns with interactive testers.
Frequently Asked Questions
What is the File Path (Unix) regex pattern?
Matches absolute Unix/Linux file paths starting with forward slash. Validates path component characters.
How do I use the File Path (Unix) regex?
Use the pattern /^\/(?:[a-zA-Z0-9._-]+\/?)*$/ in your code. In JavaScript: new RegExp('^\/(?:[a-zA-Z0-9._-]+\/?)*$', ''). Test it above with your own input.
What does this File Path (Unix) regex match?
This pattern matches: "/usr/local/bin/node". It does NOT match: "C:\Windows". Path validation, file system operations, log parsing.
Is the File Path (Unix) regex beginner-friendly?
This pattern is rated Beginner. It uses basic regex syntax and is easy to understand.
What languages support the File Path (Unix) regex?
This pattern works in all major programming languages including JavaScript, Python, Java, C#, Go, Ruby, PHP, and more. Syntax may vary slightly between regex engines.
Can I modify the File Path (Unix) regex for my use case?
Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.
Related Tools
JSON Object Regex
Beginner Data Formats pattern
CSV Row Regex
Advanced Data Formats pattern
XML Tag with Content Regex
Intermediate Data Formats pattern
YAML Key-Value Regex
Beginner Data Formats pattern
Log Entry (Common Log Format) Regex
Advanced Data Formats pattern
INI Section Regex
Beginner Data Formats pattern