Reputation: 4776
I have a next string - "#Value# #value2# (#value3#) .. #valueN#"
I need to write an regexp to get an array ["Value", "#value2#", "#value3#", "valueN"]
I've tryied next:
var regexp = /#([A-z]+)#/gi;
var string = "#Value# #value2# (#value3#) .. #valueN#";
string.match(regexp);
But I get only first and last entry of expression in the string, but I need to get all entries.
Notice that the entire string can change over the time, I need to get all entries of text between #
symbols.
Thx for any advance.
Upvotes: 0
Views: 190
Reputation: 369034
The regular expression is missing digit part ([0-9]
or \d
):
> "#Value# #value2# (#value3#) .. #valueN#".match(/#[a-z\d]+#/ig)
["#Value#", "#value2#", "#value3#", "#valueN#"]
BTW, /[A-z]/
matches not only alphabet, but also characters between Z
and a
: [
, \
, ]
, ^
, _
, `
. Be careful!
/[A-z]/.test('[')
true
Maybe you mean /[A-Za-z]/
or /[A-Z]/i
or /[a-z]/i
?
Upvotes: 4