Skip to main content
Version: 3.6


Represents a pseudo-URL (PURL) - a URL pattern used to find the matching URLs on a page or html document.

A PURL is simply a URL with special directives enclosed in [] brackets. Currently, the only supported directive is [RegExp], which defines a JavaScript-style regular expression to match against the URL.

The PseudoUrl class can be constructed either using a pseudo-URL string or a regular expression (an instance of the RegExp object). With a pseudo-URL string, the matching is always case-insensitive. If you need case-sensitive matching, use an appropriate RegExp object.

Internally, PseudoUrl class is using purlToRegExp function which parses the provided PURL and converts it to an instance of the RegExp object (in case it's not).

For example, a PURL[(\w|-)*] will match all of the following URLs:


Be careful to correctly escape special characters in the pseudo-URL string. If either [ or ] is part of the normal query string, it must be encoded as [\x5B] or [\x5D], respectively. For example, the following PURL:[\x5B]load[\x5D]=1

will match the URL:[load]=1

If the regular expression in the pseudo-URL contains a backslash character (), you need to escape it with another back backslash, as shown in the example below.

Example usage:

// Using a pseudo-URL string
const purl = new PseudoUrl('[(\\w|-)+]');

// Using a regular expression
const purl2 = new PseudoUrl(/http://www\.example\.com/pages/(\w|-)+/);

if (purl.matches('')) console.log('Match!');







  • new PseudoUrl(purl: string | RegExp): PseudoUrl
  • Parameters

    • externalpurl: string | RegExp

      A pseudo-URL string or a regular expression object. Using a RegExp instance enables more granular control, such as making the matching case-sensitive.

    Returns PseudoUrl



regex: RegExp



  • matches(url: string): boolean
  • Determines whether a URL matches this pseudo-URL pattern.


    • externalurl: string

    Returns boolean