I have the following string of javascript:
#d1{width:100px;} it looks like css code
now I wrote a regular expression that finds of an element starting with # or . in the string.
the regular expression is like this:
/(?:(#|\.)([A-Za-z0-1\-]+))/g
and the above regular expression matches successfully such strings like the above one.
but now when I tested this regular expression on the above string in Google console with then it returns false
the which I wrote was:
var str = "#d1{width:100px} " // returns undefined
var regex = / (?:(#|\.)([A-Za-z0-1\-]+)) /g //undefrined
regex.test(str) // returns false
Why it is not working?
regex = /(?:(#|\.)([A-Za-z0-1\-]+))/g?