This is driving me crazy, what is the reason this doesn’t work?
var name = data.match(/first-([A-Za-z0-9-]+)/g).replace('first-', '');
I want to replace first-joe with joe.
I also tried
var name = data.match(/first-([A-Za-z0-9-]+)/g);
var name = name.replace('first-', '');
and that doesn’t work.
However the when alerting name I get first-joe
What is the reason for this, and how do I fix it?
Thanks
matchwith/greturns an array of matches (excluding parenthesized substrings), so you would have toreplacethem individually. If you know there is exactly one match, usedata.match(/first-([A-Za-z0-9-]+)/)[1]which extracts the parenthesized substring.