regular rexpression except code example

Example 1: regex match everything except

let reg = /[^charachter_to_not_match]*/
// Example
let str = '<<1,2,3>, <4,5,6>, <7,8,9>>'
//match everything but '>'
reg = /[^>]+/g // Array(3) ["<<1,2,3", ", <4,5,6", ", <7,8,9"]
//match everything but '<' and '>'
reg = /[^<>]+/g // Array(5) ["1,2,3", ", ", "4,5,6", ", ", ...]
//match anything but '<', '>', ',' and '\s' (\s=any whitespace)
reg = /[^<>,\s]+/g // Array (9) ["1", "2", ..., "9"]

Example 2: regular rexpression except

// Search everything but strings not include 'validate'
let reg = /^((?!validate).)*$/
let str = "https://yourdomain.com/validate"

// Search by charactor, exlcue all the chars in charachter_to_not_match
let reg = /[^charachter_to_not_match]*/

Tags:

Misc Example