Skip to main content
Regexflux

Unix File Path

beginner

Matches Unix/Linux/macOS file paths.

filepathunixlinux

Pattern

/(?:/[\w.-]+)+/?/g

Try It

0 of 6 strings matched

Explanation

Matches forward-slash-separated path components. Each component is one or more word characters, dots, or hyphens. Optional trailing slash for directories.

Test Strings

Matching

  • /home/user/file.txt
  • /var/log/syslog
  • /usr/local/bin/

Non-matching

  • relative
  • C:\Windows
  • nopath

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:\/[\w.-]+)+\/?/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns