Skip to content

(regex+)

regular expression patterns across literals and RegExp constructor calls

clojure
(regex+ pattern flags?)

Where:

  1. pattern: the regex pattern to find *
  2. flags: undefined *

Expanding into:

clojure
(:or (of RegExp (arg 1 (str+ \1)))
     (regex \1 \2))

Matching:

  1. regex literals, e.g. /foo/g
  2. RegExp constructor, e.g. new RegExp("foo")

Behavior

  • Flags are not considered in the RegExp constructor variant.

Examples

Find regexes that target API routes for auditing.

clojure
(regex+ /api/)

Selects in lines { 1, 3 } but not in { 2 }:

typescript
const r1 = /api/
const r2 = /v1/
const r3 = new RegExp("api")

Locate RegExp constructors built from concatenated strings.

clojure
(regex+ /token/)

Selects in lines { 1, 3 } but not in { 2 }:

typescript
const r1 = new RegExp("token-" + suffix)
const r2 = new RegExp("session-" + suffix)
const r3 = /token-[0-9]+/

Identify regex patterns used for user-name validation across literals and constructors.

clojure
(regex+ "user-")

Selects in lines { 1, 2 } but not in { 3 }:

typescript
const r1 = /user-[a-z]+/i
const r2 = new RegExp("user-[a-z]+")
const r3 = /admin-[a-z]+/

Arguments

pattern

• String • Pattern

Does NOT support: CompositionFree-form SelectionRefinementReplacement

flags

• String • Pattern

Does NOT support: CompositionFree-form SelectionRefinementReplacement

Copyright © 2022-present Semantic Works, Inc.