Click here to Skip to main content
15,036,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My string contains
str = "Its a test string @[test_u](89) and @[test_v](91), lets try it."

And I am extracting
usernames = str.match(/([^"@\[])[^@\[]+?(?=\]\([1-9]+[0-9]*\))+/g); // ["test_u","test_v"]

And I need to extract id's in similar way and need
["89", "91"]

I have incomplete regex as
ids = str.match(/([^"(])[^@\(]+?(?=\))+/g);

Please suggest regex for extracting id's.

What I have tried:

I tried with
ids = str.match(/([^"(])[^@\(]+?(?=\))+/g);
Updated 11-Oct-19 8:12am


That will give you two matches: "89" and "91".
Your code can do what it likes with them from that point.

If you are goign to use Regexes, then get a copy of Expresso[^] - it's free, and it examines, generates, and tests Regular expressions.
Member 11748901 11-Oct-19 11:25am

I just modified
OriginalGriff 11-Oct-19 11:27am
You're welcome!
Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre -[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900