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

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -