Regex matches anything after / x / and before next /

title/x/word/c

How do I match something after /x/

but before the next one /

? (i.e. match word

)

\/x\/.+\/

matches /x/word/

, but I'm not sure how to match correctly word

(new for regex)

+3


source to share


2 answers


Use appearance and negative character class:

(?<=/x/)[^/]*

      



Watch live demo .

Take a look around without participating in the match.

+3


source


/x/([^/]*)



This is a simple regular expression. We are matching /x/

, followed by zero or more characters that are not /

. You just add the parentheses where you want to add the capture group.

-1


source







All Articles