How does js determine that a string is a regular expression

let regexp = "/ ^ [0-9] * $/";

something like this: this is a string with regular expressions in it.

so how do you tell if the content of a string is a legal regular expression?

Mar.28,2021

regular judgment
or try it out
var isreg;
try {
isreg=eval (regexp) instanceof RegExp
} catch (e) {
isreg=false
}


you can tell whether the string is regular
, but you can't tell if the rule is correct.


the demand itself is explosive. Use regularity to judge whether it is regular or not.
I really won't leave an imprint to watch the bosses play

write a simple:
beginning match begins with / matches ^ with or without. The
ending matches a free combination that ends with the ending symbol $with or without collocation / re-collocation igm.
(it's too long. I'll ignore the m first.)
the middle match really doesn't write any characters

.
/^\/\^?.*(\$?[\/|\/g|\/gi|\/i|\/ig])$/.test("/^sdk332$/ig")

this is still an excellent combination that is illegal and cannot be judged.

Menu