Can't test the javascript regex correctly -
Hello, I have the following Reagax which can not be accepted on JavaScript
If ($ (Collar) .attr ('value'). ToString (). Search ('/ (? = \ D * \ d \ D * \ d). {8,15} / g') == -1)
Where
$ (collar) .attr ('value'). ToString () = "fdsddfsd45"
I have it -1
Also I try to test it with pattern
if (pattern.test (! $ (Collar) .attr ('value'))) { Where < Pre pattern = / ^ (? = D * dD * d) {8,15} $ /
me false
< Pre> $ (collar) .attr ('value') .tstring () = "fdsddfsd45"
When I tried to test it through the desktop application, Which corresponds to this type of string "fdsddfsd45" expression (? = \ D * \ d \ D * \ D). {8,15} Do not I know this JavaScript bug? Regex in Javascript should either be a string or a regex literally in your case, should do this:
.search (/ (? = \ D * \ d \ D * \ d). {8,15} /) == -1
Note that I have removed single quotes. I have also removed the / g
flag - since you are searching for any match, you do not need it.
For completeness, when it is less useful, you have written regex as a string, but you have to save all the backslashes, or JavaScript as \ d
Even before parsing d
, regex will be reached. In this situation, you do not need a slash (for example, which uses both), unlike PHP:
s.search ('(? = \\ D * Example:
Comments
Post a Comment