/(?<=([ab]+)([bc]+))$/.exec("abc"); // ['', 'a', 'bc']
// Not ['', 'ab', 'c']Lookbehind assertion: (?<=...), (?<!...) / notebook
Lookbehind assertion: (?<=...), (?<!...)
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function getPrice(label) {
return /(?<=\$)\d+(?:\.\d*)?/.exec(label)?.[0];
}
getPrice("$10.53"); // "10.53"
getPrice("10.53"); // undefined