A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/slevithan/regex-utilities below:

slevithan/regex-utilities: 🧰 Tiny helpers for processing regex syntax

Tiny utilities that the Regex+ library makes available for reuse in its plugins and elsewhere. Useful for processing JavaScript regular expression syntax in a lightweight way, when you don't need a full regex parser and AST.

Frozen object with the following properties for tracking regex syntax context:

For all of the following functions, argument expression is the target string, and needle is the regex pattern to search for.

Arguments: expression, needle, replacement, [context]

Replaces all unescaped instances of a regex pattern in the given context, using a replacement string or function.

Examples with a replacement string
const str = '.\\.\\\\.[[\\.].].';
replaceUnescaped(str, '\\.', '@');
// → '@\\.\\\\@[[\\.]@]@'
replaceUnescaped(str, '\\.', '@', Context.DEFAULT);
// → '@\\.\\\\@[[\\.].]@'
replaceUnescaped(str, '\\.', '@', Context.CHAR_CLASS);
// → '.\\.\\\\.[[\\.]@].'

Details for the replacement argument:

Arguments: expression, needle, [pos = 0], [context]

Returns a match object for the first unescaped instance of a regex pattern in the given context, or null.

Arguments: expression, needle, [context]

Checks whether an unescaped instance of a regex pattern appears in the given context.

Arguments: expression, needle, callback, [context]

Runs a function for each unescaped match of a regex pattern in the given context. The function receives two arguments:

  1. The match object (which includes groups, index, etc.).
  2. An object with extended details (context and negated) about where the match was found.

Arguments: expression, contentsStartPos

Extracts the full contents of a group (subpattern) from the given expression, accounting for escaped characters, nested groups, and character classes. The group is identified by the position where its contents start (the string index just after the group's opening delimiter). Returns the rest of the string if the group is unclosed.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4