简体   繁体   中英

how to match everything except a particular pattern using regex

After a half hour searching I failed. Now I am trying to match everything except the given word.

I am trying to match /user/* except one word login .

Examples:

/user/test  match!
/user/loginno match!
/user/login  not match!

My regex is: ^/user/(?!login)(.*) but I can not make /user/loginno match ):

^/user/(?!login\\b)(.*)

I altered your regex by requiring there to be a word boundary after login for the lookahead to match, eg login followed by a non alphanumerical character (space or / for example). It seems to work.

^\/user\/(?!login\b)(.*)

这是转义正斜杠后的更正正则表达式

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM