Skip to content

lookbehind not supported on safari < 17 #143

@rhysburnie

Description

@rhysburnie

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch anchorme@3.0.5 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/anchorme/dist/node/regex.js b/node_modules/anchorme/dist/node/regex.js
index 817f906..573a757 100644
--- a/node_modules/anchorme/dist/node/regex.js
+++ b/node_modules/anchorme/dist/node/regex.js
@@ -15,7 +15,14 @@ var fqdn = "(((".concat(protocol, ")?(").concat(domain, "|").concat(ipv4, ")(?=\
 exports.email = "\\b(mailto:)?".concat(emailAddress, "@(").concat(domain, "|").concat(ipv4, ")");
 exports.url = "(".concat(fqdn, ")").concat(path, "?");
 exports.file = "(file:\\/\\/\\/)(?:[a-z]+:(?:\\/|\\\\)+)?([\\w.]+(?:[\\/\\\\]?)+)+";
-exports.final = "(?<=\\b|_)((".concat(exports.email, ")|(").concat(exports.file, ")|(").concat(exports.url, "))(\\b)?");
+
+try {
+  new RegExp('(?<=\\b|_)'); // safari < 17 doesnt like this
+  exports.final = "(?<=\\b|_)((".concat(exports.email, ")|(").concat(exports.file, ")|(").concat(exports.url, "))(\\b)?");
+} catch(err) {
+  exports.final = "(?:\\b|_)((".concat(exports.email, ")|(").concat(exports.file, ")|(").concat(exports.url, "))(\\b)?");
+}
+
 exports.finalRegex = new RegExp(exports.final, "gi");
 // for validation purposes
 exports.ipRegex = new RegExp("^(".concat(ipv4, "|").concat(ipv6, ")$"), "i");

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions