0

It's possible to get list of group items from regex object? For example, i have this regex:

var someRegex = /hello\s(.*?), i have (\d+) friends! (?:Bye)/;

I want to be able to get:

['(.*?)', '(\\d+)'];

(Note that i don't want to get the 'Bye' group because it has '?:' mark..)

Thanks!

1 Answer 1

1
\((?!\?:)[^(]*\)

Try this.See demo.

https://regex101.com/r/bN8dL3/7

var re = /\((?!\?:)[^(]*\)/gi;
var str = 'hello\s(.*?), i have (\d+) friends! (?:Bye)';
var m;

while ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
// View your result using the m-variable.
// eg m[0] etc.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.