Regex for Absolute Unix Path
Regex Pattern
^\/(?:[^\/\0]+\/)*[^\/\0]*$Absolute filesystem path starting with /
Quick Answer
The regex pattern for absolute unix path is `^\/(?:[^\/\0]+\/)*[^\/\0]*$`. Absolute filesystem path starting with /. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| /home/user/file.txt | ✓ Matches |
| /var/log/syslog | ✓ Matches |
| / | ✓ Matches |
| relative/path | ✗ No match |
| C:\\Windows | ✗ No match |
| ../parent | ✗ No match |
Code Examples
javascript
const regex = /^\\/(?:[^\\/\0]+\\/)*[^\\/\0]*$/; const isValid = regex.test(value);
python
import re
pattern = r'^\/(?:[^\/\0]+\/)*[^\/\0]*$'
if re.match(pattern, value):
print("valid")ruby
pattern = /^\/(?:[^\/\0]+\/)*[^\/\0]*$/ if value =~ pattern puts "valid" end
php
if (preg_match('/^\\/(?:[^\\/\0]+\\/)*[^\\/\0]*$/', $value)) {
echo "valid";
}java
String pattern = "^\\/(?:[^\\/\\0]+\\/)*[^\\/\\0]*$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
File Extension
File extension at the end of a filename
Image File Extension
Common image file extensions
Video File Extension
Common video file extensions
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
URL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs