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

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -