Home > Blockchain >  Why regex function not works using multiple values?
Why regex function not works using multiple values?

Time:12-25

I work on projects it works fine but when I add value color then it doesn't work?

here is my Js Fiddle Link, when we use #color=(#333) then it should change the color of the background button but it doesn't

same like in #size=(1) it adds a class in button but now the code doesn't work

I just add regex function and the code stopped working Please check the jsFiddle

here these lines of code stop working

var color = getAttr(info, "color");
var size = getAttr(info, "size");

While the rest of the code works fine, Any help or advice is highly appreciated.

CodePudding user response:

You regex seems wrong on the second-half

/(?:(\#[a-zA-Z]{4,})=\(([a-z A-Z]{4,})\))/g

This would indicates the string should have

  1. hash #
  2. letter-ONLY character (minimum 4 characters)
  3. equal =
  4. another letter-ONLY character (minimum 4 characters) in brackets

Thus, your example #color=(#333) not working bcoz it has hash # and #size=(1) not working bcoz it is not letter and only have 1 character.

SOLUTION: You should use like this instead:

/(?:(\#[a-zA-Z] )=\(([^\)] )\))/g
  • Related