Skip to main content
Regexflux

Relative File Path

beginner

Matches relative file paths starting with ./ or ../.

filepathrelativeimport

Pattern

/(?:\.{1,2}/)+[\w./+-]+/g

Try It

0 of 6 strings matched

Explanation

Matches paths starting with ./ (current directory) or ../ (parent directory), followed by path components separated by forward slashes.

Test Strings

Matching

  • ./src/index.ts
  • ../package.json
  • ../../lib/utils.ts

Non-matching

  • /absolute/path
  • just-a-file
  • C:\path

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

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

Related Patterns