regex - How can I capture the string "word1/word2/*" with a regular expression? -


i need build regular expression accepts following pattern:

word1/word2/*

word1/*

"word2" optional, , needs end "/*".

i tried regexp:

 (word1)/(word2)?/\* 

it matches input: word1/word2/*

but not this: word1/*

you need move first / following capture group (parenthesized subexpression):

(word1)(/word2)?/\* 

if want capture word2 without /, introduce additional capture group:

(word1)(/(word2))?/\* 

depending on environment, more sophisticated solutions may available avoid additional capture group (non-capturing groups, look-around assertions).


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -