Reputation: 2667
Okay so I currently have:
/(#([\"]))/g;
I want to be able to check for a string like:
#23ad23"
Whats wrong with my regex?
Upvotes: 0
Views: 98
Reputation: 9158
For minimum match count (bigger-length matches): #(.+)\"
For maximum match count (smaller-length matches): #(.+?)\"
Upvotes: 1
Reputation: 58531
Your regex (/(#([\"]))/g
) breaks down like this:
without start/end delimiters/flags and capturing braces..
#[\"]
which just means #
, followed by "
, but the square brackets for the class are unnecessary, as there is only one item, so equivalent to...
#"
I think you want to match all characters between #
and "
inclusive (and captured exclusively).
Start with regex like this:
#.+?"
Which means #
followed by anything (.
) one or more times (+
) un-greedily (?
) followed by "
so with the capturing brackets, and delimeters...
/(#(.+?)")/g
Upvotes: 2
Reputation: 108500
Is this how you mean?
/(#([^\"]+))/g;
This will include everything until it reaches the "
char.
Upvotes: 1