Find list of strings that matches a pattern that start with a special character « and end with a special character »

You can match using unicode and replace the unicodes later

Unicode finder

let str = `«Name» has an account on the bank «Bank Name»`

let final = str.match(/\u00AB.*?\u00BB/gu).map(v=>v.replace(/\u00AB|\u00BB/g,''))

console.log(final)

Alternatively you can use exec and get the value from captured group

let str = `«Name» has an account on the bank «Bank Name»`
let final = []
let reg = /\u00AB(.*?)\u00BB/gu

while ((arr = reg.exec(str)) != null) {
  final.push(arr[1])
}

console.log(final)

Leave a Comment