I want to capture all variable names after "define" keyword (im using js).
I already tried this:
(?<=define\s)(?:([a-zA-Z_]\w*),?\s?)+
but it only captures last occurrence, but i want to get all of them. example string :
define x, y, z, a
link here regex101
If you are using a browser that supports an infinite quantifier in the lookbehind assertion:
(?<=define\s[\w,\s]*)[a-zA-Z_]\w*
The pattern matches:
(?<= Positive lookbehind, assert what is at the left is
define\s Match define followed by a whitspace char[\w,\s]* Match optional allowed chars in between) Close lookbehind[a-zA-Z_]\w* Match a single char a-zA-Z or _ and optional word charsconst s = "define x, y, z, a";
const regex = /(?<=define\s[\w,\s]*)[a-zA-Z_]\w*/g;
console.log(s.match(regex));