-3
 "<circle cx='24' cy='24' fill='#CA3737' r='24'>".match(
            new RegExp("((?![0-9])(\w+)-*(\w*) *= *)(([0-9.]+)|('.+?')|(\w+))",'g')
     )

giving null while this expression is giving correct output on http://regexr.com/

i need a regular expression to find attributes of a tag.

user3785155
  • 69
  • 1
  • 4
  • 2
    This question is [off-topic (#1)](/help/on-topic). Please review [ask] and include a [mcve] along with a full description of the problem you're having. – zzzzBov Jan 29 '17 at 06:19

1 Answers1

0

You can simply use the regex by surrounding it with /.The problem is your code was that new RegExp results in a regex that is different from what you expect

Your regex:

/((?![0-9])(\w+)-*(\w*) *= *)(([0-9.]+)|('.+?')|(\w+))/g

new RegExp() output

/\/((?![0-9])(w+)-*(w*) *= *)(([0-9.]+)|('.+?')|(w+))/g

The below snippet gives the same result as regexr.com

console.log("<circle cx='24' cy='24' fill='#CA3737' r='24'>".match(
           /((?![0-9])(\w+)-*(\w*) *= *)(([0-9.]+)|('.+?')|(\w+))/g
     )
            );
Shubham Khatri
  • 270,417
  • 55
  • 406
  • 400