Reputation: 23563
I have a regex which is working according to regex101.com, however when I use it in my JS I get an error:
Uncaught SyntaxError: Invalid regular expression flags
const bandsReduced = bands.map((item)=>{
return item.replace(/the|a/gAi,'');
});
Upvotes: 1
Views: 1538
Reputation: 23563
The ^ character is used in JavaScript to limit the search to the beginning of the string:
const bandsReduced = bands.map((item)=>{
return item.replace(/^the|^a/ig,'');
});
Upvotes: 1
Reputation: 7077
A
is not a flag in JavaScript.Valid flags are g
,i
, m
, u
, y
. See the documentation here: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
Different languages have slightly different regex syntax, in regex101 you can change the language as per image below.
(as mentioned by elcanrs in the comment)
Upvotes: 2