How to use regex with not ^ and capture groups? -


how use not operator ^ capture groups in regex.

example: have 2 urls coming in: http://api.example.com , http://example.com

how make capture group on urls not contain api.

how thought var notapi = /(^api)/;

regex has negative lookaheads , lookbehinds. spirit is: look, don't move forward.

this negative lookahead:

(?!nomatch) 

and negative lookbehind:

(?<!nomatch) 

you can incorporate these lookarounds regex this:

var notapi = /^((?!api).)*$/; 

take @ this answer - explains how works.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

post - imageshack API cURL -