javascript

A mistake with RegExes in JavaScript

In the past months I've made a subtle JavaScript programming error repeatedly. In an effort to not make this mistake again, I'll discus this error here.

Very often I write statements such as the following:

if (myString.search(/lorem/)) {
}

(Of course, the actual regex used differs).

According to the documentation, the search method expects a RegEx object. A RegEx object is conveniently created on the fly using the // shorthand.

Read the rest of this entry »