Can I use a regular expression in querySelectorAll?

You can’t really use a regular expression in a selector but CSS selectors are powerful enough for your need with a “starts with” syntax inspired by regexes.

You can use a substring matching attribute selectors : link[type^=service]

Reads “Nodes of type link with an attribute type starting with “service”

From the formal specification:

[att^=val]

Represents an element with the att attribute whose value begins with the prefix “val”. If “val” is the empty string then the selector does not represent anything.

Working JSFiddle

Leave a Comment