ts-regex-builder
Advanced tools
Comparing version 1.8.1 to 1.8.2
@@ -8,9 +8,4 @@ "use strict"; | ||
const pattern = (0, _encoder.encode)(sequence).pattern; | ||
ensureUnicodeFlagIfNeeded(pattern, flags); | ||
const flagsString = encodeFlags(flags ?? {}); | ||
if (!flags?.unicode) { | ||
const unicodeModePattern = getUnicodeModePattern(pattern); | ||
if (unicodeModePattern) { | ||
throw new Error(`The pattern "${unicodeModePattern}" requires Unicode-aware mode. Please ensure the "unicode" flag is set.`); | ||
} | ||
} | ||
return new RegExp(pattern, flagsString); | ||
@@ -32,7 +27,12 @@ } | ||
} | ||
const unicodeModePatterns = /(?:\\u|\\p|\\P)\{.+?\}/; | ||
function getUnicodeModePattern(pattern) { | ||
const unicodeModePatterns = /(?<!\\)(?:\\u|\\[pP])\{.+?\}/; | ||
function ensureUnicodeFlagIfNeeded(pattern, flags) { | ||
if (flags?.unicode) { | ||
return; | ||
} | ||
const match = pattern.match(unicodeModePatterns); | ||
return match?.[0] ?? null; | ||
if (match) { | ||
throw new Error(`Pattern "${match?.[0]}" requires "unicode" flag to be set.`); | ||
} | ||
} | ||
//# sourceMappingURL=builders.js.map |
@@ -8,21 +8,19 @@ "use strict"; | ||
exports.negated = negated; | ||
var _encoder = require("../encoder.js"); | ||
var _utils = require("../utils.js"); | ||
function charClass(...elements) { | ||
if (!elements.length) { | ||
throw new Error('`charClass` should receive at least one element'); | ||
throw new Error('Expected at least one element'); | ||
} | ||
return { | ||
chars: elements.map(c => c.chars).flat(), | ||
ranges: elements.map(c => c.ranges ?? []).flat() | ||
ranges: elements.map(c => c.ranges ?? []).flat(), | ||
encode: encodeCharClass | ||
}; | ||
} | ||
function charRange(start, end) { | ||
if (start.length !== 1) { | ||
throw new Error('`charRange` should receive only single character `start` string'); | ||
if (start.length !== 1 || end.length !== 1) { | ||
throw new Error(`Expected single characters, but received "${start}" & "${end}"`); | ||
} | ||
if (end.length !== 1) { | ||
throw new Error('`charRange` should receive only single character `end` string'); | ||
} | ||
if (start > end) { | ||
throw new Error('`start` should be before or equal to `end`'); | ||
[start, end] = [end, start]; | ||
} | ||
@@ -34,21 +32,36 @@ return { | ||
end | ||
}] | ||
}], | ||
encode: encodeCharClass | ||
}; | ||
} | ||
function anyOf(characters) { | ||
const chars = characters.split('').map(c => escapeCharClass(c)); | ||
if (chars.length === 0) { | ||
throw new Error('`anyOf` should received at least one character'); | ||
} | ||
function anyOf(chars) { | ||
(0, _utils.ensureText)(chars); | ||
return { | ||
chars | ||
chars: chars.split('').map(escapeChar), | ||
encode: encodeCharClass | ||
}; | ||
} | ||
function negated(element) { | ||
return (0, _encoder.encodeCharClass)(element, true); | ||
return encodeCharClass.call(element, true); | ||
} | ||
const inverted = exports.inverted = negated; | ||
function escapeCharClass(text) { | ||
function escapeChar(text) { | ||
return text.replace(/[\]\\]/g, '\\$&'); | ||
} | ||
function encodeCharClass(isNegated) { | ||
const hyphen = this.chars.includes('-') ? '-' : ''; | ||
const caret = this.chars.includes('^') ? '^' : ''; | ||
const otherChars = this.chars.filter(c => c !== '-' && c !== '^').join(''); | ||
const ranges = this.ranges?.map(({ | ||
start, | ||
end | ||
}) => `${start}-${end}`).join('') ?? ''; | ||
const negation = isNegated ? '^' : ''; | ||
let pattern = `[${negation}${ranges}${otherChars}${caret}${hyphen}]`; | ||
if (pattern === '[^-]') pattern = '[\\^-]'; | ||
return { | ||
precedence: 'atom', | ||
pattern | ||
}; | ||
} | ||
//# sourceMappingURL=char-class.js.map |
"use strict"; | ||
exports.any = void 0; | ||
exports.char = char; | ||
exports.notWord = exports.notWhitespace = exports.notDigit = exports.nonWord = exports.nonWhitespace = exports.nonDigit = exports.digit = void 0; | ||
exports.unicodeProperty = unicodeProperty; | ||
exports.word = exports.whitespace = void 0; | ||
exports.word = exports.whitespace = exports.notWord = exports.notWhitespace = exports.notDigit = exports.nonWord = exports.nonWhitespace = exports.nonDigit = exports.digit = exports.any = void 0; | ||
const any = exports.any = { | ||
@@ -45,21 +41,2 @@ precedence: 'atom', | ||
const notWhitespace = exports.notWhitespace = nonWhitespace; | ||
function char(codePoint) { | ||
if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff) { | ||
throw new RangeError(`Expected a valid unicode code point but received ${codePoint}`); | ||
} | ||
let escape = codePoint < 0x10000 ? `\\u${codePoint.toString(16).padStart(4, '0')}` : `\\u{${codePoint.toString(16)}}`; | ||
return { | ||
precedence: 'atom', | ||
pattern: escape, | ||
chars: [escape] | ||
}; | ||
} | ||
function unicodeProperty(property, value) { | ||
const escape = `\\p{${property}${value ? `=${value}` : ''}}`; | ||
return { | ||
precedence: 'atom', | ||
pattern: escape, | ||
chars: [escape] | ||
}; | ||
} | ||
//# sourceMappingURL=char-escape.js.map |
@@ -7,3 +7,3 @@ "use strict"; | ||
if (alternatives.length === 0) { | ||
throw new Error('`choiceOf` should receive at least one alternative'); | ||
throw new Error('Expected at least one alternative'); | ||
} | ||
@@ -10,0 +10,0 @@ const encodedAlternatives = alternatives.map(c => (0, _encoder.encode)(c)); |
@@ -7,20 +7,24 @@ "use strict"; | ||
var _encoder = require("../encoder.js"); | ||
var _utils = require("../utils.js"); | ||
function zeroOrMore(sequence, options) { | ||
const elements = (0, _utils.ensureElements)(sequence); | ||
return { | ||
precedence: 'sequence', | ||
pattern: `${(0, _encoder.encodeAtomic)(sequence)}*${options?.greedy === false ? '?' : ''}` | ||
pattern: `${(0, _encoder.encodeAtomic)(elements)}*${options?.greedy === false ? '?' : ''}` | ||
}; | ||
} | ||
function oneOrMore(sequence, options) { | ||
const elements = (0, _utils.ensureElements)(sequence); | ||
return { | ||
precedence: 'sequence', | ||
pattern: `${(0, _encoder.encodeAtomic)(sequence)}+${options?.greedy === false ? '?' : ''}` | ||
pattern: `${(0, _encoder.encodeAtomic)(elements)}+${options?.greedy === false ? '?' : ''}` | ||
}; | ||
} | ||
function optional(sequence, options) { | ||
const elements = (0, _utils.ensureElements)(sequence); | ||
return { | ||
precedence: 'sequence', | ||
pattern: `${(0, _encoder.encodeAtomic)(sequence)}?${options?.greedy === false ? '?' : ''}` | ||
pattern: `${(0, _encoder.encodeAtomic)(elements)}?${options?.greedy === false ? '?' : ''}` | ||
}; | ||
} | ||
//# sourceMappingURL=quantifiers.js.map |
@@ -5,7 +5,5 @@ "use strict"; | ||
var _encoder = require("../encoder.js"); | ||
var _utils = require("../utils.js"); | ||
function repeat(sequence, options) { | ||
const elements = Array.isArray(sequence) ? sequence : [sequence]; | ||
if (elements.length === 0) { | ||
throw new Error('`repeat` should receive at least one element'); | ||
} | ||
const elements = (0, _utils.ensureElements)(sequence); | ||
if (typeof options === 'number') { | ||
@@ -12,0 +10,0 @@ return { |
@@ -5,5 +5,5 @@ "use strict"; | ||
exports.encodeAtomic = encodeAtomic; | ||
exports.encodeCharClass = encodeCharClass; | ||
var _utils = require("./utils.js"); | ||
function encode(sequence) { | ||
const elements = Array.isArray(sequence) ? sequence : [sequence]; | ||
const elements = (0, _utils.ensureElements)(sequence); | ||
const encoded = elements.map(n => encodeElement(n)); | ||
@@ -26,17 +26,17 @@ if (encoded.length === 1) { | ||
} | ||
if (typeof element === 'object' && element instanceof RegExp) { | ||
if (element instanceof RegExp) { | ||
return encodeRegExp(element); | ||
} | ||
if (typeof element === 'object' && 'pattern' in element) { | ||
return element; | ||
if (typeof element === 'object') { | ||
if ('pattern' in element) { | ||
return element; | ||
} | ||
if ('encode' in element) { | ||
return element.encode(); | ||
} | ||
} | ||
if (typeof element === 'object' && 'chars' in element) { | ||
return encodeCharClass(element); | ||
} | ||
throw new Error(`\`encodeElement\`: unknown element: ${JSON.stringify(element, null, 2)}`); | ||
throw new Error(`Unsupported element. Received: ${JSON.stringify(element, null, 2)}`); | ||
} | ||
function encodeText(text) { | ||
if (text.length === 0) { | ||
throw new Error('`encodeText`: received text should not be empty'); | ||
} | ||
(0, _utils.ensureText)(text); | ||
return { | ||
@@ -55,32 +55,4 @@ precedence: text.length === 1 ? 'atom' : 'sequence', | ||
function isAtomicPattern(pattern) { | ||
if (pattern.length === 1) { | ||
return true; | ||
} | ||
if (pattern.startsWith('[') && pattern.endsWith(']') && pattern.match(/[[\]]/g)?.length === 2) { | ||
return true; | ||
} | ||
if (pattern.startsWith('(') && pattern.endsWith(')') && pattern.match(/[()]/g)?.length === 2) { | ||
return true; | ||
} | ||
return false; | ||
return pattern.length === 1 || /^\[[^[\]]*\]$/.test(pattern) || /^\([^()]*\)$/.test(pattern); | ||
} | ||
function encodeCharClass(element, isNegated) { | ||
if (!element.chars.length && !element.ranges?.length) { | ||
throw new Error('Character class should contain at least one character or character range'); | ||
} | ||
const hyphen = element.chars.includes('-') ? '-' : ''; | ||
const caret = element.chars.includes('^') ? '^' : ''; | ||
const otherChars = element.chars.filter(c => c !== '-' && c !== '^').join(''); | ||
const ranges = element.ranges?.map(({ | ||
start, | ||
end | ||
}) => `${start}-${end}`).join('') ?? ''; | ||
const negation = isNegated ? '^' : ''; | ||
let pattern = `[${negation}${ranges}${otherChars}${caret}${hyphen}]`; | ||
if (pattern === '[^-]') pattern = '[\\^-]'; | ||
return { | ||
precedence: 'atom', | ||
pattern | ||
}; | ||
} | ||
function escapeText(text) { | ||
@@ -87,0 +59,0 @@ return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); |
@@ -36,3 +36,3 @@ "use strict"; | ||
get: function () { | ||
return _charEscape.char; | ||
return _unicode.char; | ||
} | ||
@@ -190,6 +190,12 @@ }); | ||
}); | ||
Object.defineProperty(exports, "unicodeChar", { | ||
enumerable: true, | ||
get: function () { | ||
return _unicode.unicodeChar; | ||
} | ||
}); | ||
Object.defineProperty(exports, "unicodeProperty", { | ||
enumerable: true, | ||
get: function () { | ||
return _charEscape.unicodeProperty; | ||
return _unicode.unicodeProperty; | ||
} | ||
@@ -234,2 +240,3 @@ }); | ||
var _repeat = require("./constructs/repeat.js"); | ||
var _unicode = require("./constructs/unicode.js"); | ||
//# sourceMappingURL=index.js.map |
@@ -6,7 +6,5 @@ "use strict"; | ||
var _anchors = require("../constructs/anchors.js"); | ||
var _charClass = require("../constructs/char-class.js"); | ||
var _charEscape = require("../constructs/char-escape.js"); | ||
var _choiceOf = require("../constructs/choice-of.js"); | ||
var _repeat = require("../constructs/repeat.js"); | ||
const hexDigit = (0, _charClass.charClass)(_charEscape.digit, (0, _charClass.charRange)('a', 'f')); | ||
const hexDigit = /[0-9a-f]/; | ||
const hexColorFinder = exports.hexColorFinder = (0, _builders.buildRegExp)(['#', (0, _choiceOf.choiceOf)((0, _repeat.repeat)(hexDigit, 6), (0, _repeat.repeat)(hexDigit, 3)), _anchors.wordBoundary], { | ||
@@ -13,0 +11,0 @@ ignoreCase: true, |
import type { EncodedRegex } from '../types'; | ||
/** | ||
* Start of string anchor. Matches the start of of string. In `multiline` mode, also matches immediately following a newline. | ||
*/ | ||
export declare const startOfString: EncodedRegex; | ||
/** | ||
* End of string anchor. Matches the end of a string. In `multiline` mode, also matches immediately preceding a newline. | ||
*/ | ||
export declare const endOfString: EncodedRegex; | ||
/** | ||
* Word boundary anchor. Matches the position where one side is a word character (alphanumeric or underscore) and the other side is a non-word character (anything else). | ||
*/ | ||
export declare const wordBoundary: EncodedRegex; | ||
/** | ||
* Non-word boundary anchor. Matches the position where both sides are word characters. | ||
*/ | ||
export declare const nonWordBoundary: EncodedRegex; | ||
@@ -6,0 +18,0 @@ /** |
import type { CharacterClass, CharacterEscape, EncodedRegex } from '../types'; | ||
/** | ||
* Creates a character class which matches any one of the given characters. | ||
* | ||
* @param elements - Member characters or character ranges. | ||
* @returns Character class. | ||
*/ | ||
export declare function charClass(...elements: Array<CharacterClass | CharacterEscape>): CharacterClass; | ||
/** | ||
* Creates a character class which matches any one of the characters in the range. | ||
* | ||
* @param start - Start of the range (single character). | ||
* @param end - End of the range (single character). | ||
* @returns Character class. | ||
*/ | ||
export declare function charRange(start: string, end: string): CharacterClass; | ||
export declare function anyOf(characters: string): CharacterClass; | ||
/** | ||
* Creates a character class which matches any one of the given characters. | ||
* | ||
* @param chars - Characters to match. | ||
* @returns Character class. | ||
*/ | ||
export declare function anyOf(chars: string): CharacterClass; | ||
/** | ||
* Creates a negated character class which matches any character that is not in the given character class. | ||
* | ||
* @param element - Character class or character escape to negate. | ||
* @returns Negated character class. | ||
*/ | ||
export declare function negated(element: CharacterClass | CharacterEscape): EncodedRegex; | ||
@@ -6,0 +31,0 @@ /** |
@@ -7,7 +7,25 @@ import type { CharacterEscape, EncodedRegex } from '../types'; | ||
export declare const any: EncodedRegex; | ||
/** | ||
* Matches any digit (0-9). | ||
*/ | ||
export declare const digit: CharacterEscape; | ||
/** | ||
* Matches any non-digit (0-9) character. | ||
*/ | ||
export declare const nonDigit: CharacterEscape; | ||
/** | ||
* Matches any word character (alphanumeric or underscore). | ||
*/ | ||
export declare const word: CharacterEscape; | ||
/** | ||
* Matches any non-word (alphanumeric or underscore) character. | ||
*/ | ||
export declare const nonWord: CharacterEscape; | ||
/** | ||
* Matches any whitespace character (space, tab, newline, etc.). | ||
*/ | ||
export declare const whitespace: CharacterEscape; | ||
/** | ||
* Matches any non-whitespace (space, tab, newline, etc.) character. | ||
*/ | ||
export declare const nonWhitespace: CharacterEscape; | ||
@@ -26,27 +44,1 @@ /** | ||
export declare const notWhitespace: CharacterEscape; | ||
/** | ||
* Unicode character code point escape. | ||
* | ||
* Regex pattern: | ||
* - `\uXXXX`: 4-digit hex escape for code points below 0x10000. | ||
* - `\u{X}`: Unicode code point escape for code points above 0xFFFF. | ||
* | ||
* Note: for code points above 0xFFFF, the regex must be [unicode-aware](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode#unicode-aware_mode). | ||
* | ||
* @param codePoint The code point of the character to escape. | ||
* @returns A character class representing the unicode escape. | ||
*/ | ||
export declare function char(codePoint: number): CharacterEscape; | ||
/** | ||
* Unicode property escape matching a set of characters specified by a Unicode property. | ||
* | ||
* Regex pattern: `\p{Property}` or `\p{Property=Value}` | ||
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Unicode_character_class_escape | ||
* | ||
* Note: the regex must be [unicode-aware](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode#unicode-aware_mode). | ||
* | ||
* @param property Unicode property name. | ||
* @param value Unicode property value (optional). | ||
* @returns A character class representing the unicode property escape. | ||
*/ | ||
export declare function unicodeProperty(property: string, value?: string): CharacterEscape; |
import type { EncodedRegex, RegexSequence } from '../types'; | ||
/** | ||
* Creates a disjunction (choice of) which matches any of the alternatives. | ||
* | ||
* @param alternatives - Alternatives to choose from. | ||
* @returns Choice of alternatives. | ||
*/ | ||
export declare function choiceOf(...alternatives: RegexSequence[]): EncodedRegex; |
@@ -5,4 +5,22 @@ import type { EncodedRegex, RegexSequence } from '../types'; | ||
} | ||
/** | ||
* Creates a quantifier which matches zero or more of the given elements. | ||
* | ||
* @param sequence - Elements to match zero or more of. | ||
* @param options - Quantifier options. | ||
*/ | ||
export declare function zeroOrMore(sequence: RegexSequence, options?: QuantifierOptions): EncodedRegex; | ||
/** | ||
* Creates a quantifier which matches one or more of the given elements. | ||
* | ||
* @param sequence - Elements to match one or more of. | ||
* @param options - Quantifier options. | ||
*/ | ||
export declare function oneOrMore(sequence: RegexSequence, options?: QuantifierOptions): EncodedRegex; | ||
/** | ||
* Creates a quantifier which matches zero or one of the given elements. | ||
* | ||
* @param sequence - Elements to match zero or one of. | ||
* @param options - Quantifier options. | ||
*/ | ||
export declare function optional(sequence: RegexSequence, options?: QuantifierOptions): EncodedRegex; |
import type { EncodedRegex, RegexSequence } from '../types'; | ||
/** | ||
* Groups the given sequence into a single element. | ||
* | ||
* @param sequence - Sequence to group. | ||
*/ | ||
export declare function regex(sequence: RegexSequence): EncodedRegex; |
import type { EncodedRegex, RegexSequence } from '../types'; | ||
/** | ||
* Options for the `repeat` function. | ||
* | ||
* @param min - Minimum number of times to match. | ||
* @param max - Maximum number of times to match (default: unlimited). | ||
* @param greedy - Whether to use greedy quantifiers (default: true). | ||
*/ | ||
export type RepeatOptions = number | { | ||
@@ -7,2 +14,8 @@ min: number; | ||
}; | ||
/** | ||
* Creates a quantifier which matches the given sequence a specific number of times. | ||
* | ||
* @param sequence - Sequence to match. | ||
* @param options - Quantifier options. | ||
*/ | ||
export declare function repeat(sequence: RegexSequence, options: RepeatOptions): EncodedRegex; |
@@ -1,4 +0,3 @@ | ||
import type { CharacterClass, EncodedRegex, RegexSequence } from './types'; | ||
import type { EncodedRegex, RegexSequence } from './types'; | ||
export declare function encode(sequence: RegexSequence): EncodedRegex; | ||
export declare function encodeAtomic(sequence: RegexSequence): string; | ||
export declare function encodeCharClass(element: CharacterClass, isNegated?: boolean): EncodedRegex; |
@@ -9,3 +9,3 @@ export type * from './types'; | ||
export { charClass, charRange, anyOf, negated, inverted } from './constructs/char-class'; | ||
export { any, digit, nonDigit, word, nonWord, whitespace, nonWhitespace, notDigit, notWhitespace, notWord, char, unicodeProperty, } from './constructs/char-escape'; | ||
export { any, digit, nonDigit, word, nonWord, whitespace, nonWhitespace, notDigit, notWhitespace, notWord, } from './constructs/char-escape'; | ||
export { choiceOf } from './constructs/choice-of'; | ||
@@ -19,1 +19,2 @@ export { lookahead } from './constructs/lookahead'; | ||
export { repeat } from './constructs/repeat'; | ||
export { char, unicodeChar, unicodeProperty } from './constructs/unicode'; |
@@ -15,3 +15,3 @@ export type ArrayOrSingle<T> = T[] | T; | ||
*/ | ||
export type RegexConstruct = EncodedRegex | CharacterClass; | ||
export type RegexConstruct = EncodedRegex | LazyEncodableRegex; | ||
/** | ||
@@ -29,3 +29,6 @@ * Encoded regex pattern with information about its type (atom, sequence) | ||
} | ||
export interface CharacterClass { | ||
export interface LazyEncodableRegex { | ||
encode: () => EncodedRegex; | ||
} | ||
export interface CharacterClass extends LazyEncodableRegex { | ||
chars: string[]; | ||
@@ -32,0 +35,0 @@ ranges?: CharacterRange[]; |
{ | ||
"name": "ts-regex-builder", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"description": "Maintainable regular expressions for TypeScript and JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/index.js", |
@@ -24,3 +24,3 @@ [![npm version](https://badge.fury.io/js/ts-regex-builder.svg)](https://badge.fury.io/js/ts-regex-builder) | ||
// TS Regex Builder DSL | ||
const hexDigit = charClass(charRange('a', 'f'), charRange('A', 'F'), charRange('0', '9')); | ||
const hexDigit = /[a-fA-F0-9]/; // or: charClass(charRange('a', 'f'), charRange('A', 'F'), charRange('0', '9')); | ||
@@ -120,5 +120,5 @@ const hexColor = buildRegExp([ | ||
| -------------------------------- | ------------ | ------------------------------------------------- | | ||
| `zeroOrMore(x)` | `x*` | Zero or more occurence of a pattern | | ||
| `oneOrMore(x)` | `x+` | One or more occurence of a pattern | | ||
| `optional(x)` | `x?` | Zero or one occurence of a pattern | | ||
| `zeroOrMore(x)` | `x*` | Zero or more occurrence of a pattern | | ||
| `oneOrMore(x)` | `x+` | One or more occurrence of a pattern | | ||
| `optional(x)` | `x?` | Zero or one occurrence of a pattern | | ||
| `repeat(x, n)` | `x{n}` | Pattern repeats exact number of times | | ||
@@ -130,20 +130,2 @@ | `repeat(x, { min: n, })` | `x{n,}` | Pattern repeats at least given number of times | | ||
### Character classes | ||
| Character class | Regex Syntax | Description | | ||
| ---------------------- | ------------ | ------------------------------------------------- | | ||
| `any` | `.` | Any character | | ||
| `word` | `\w` | Word character: letter, digit, underscore | | ||
| `digit` | `\d` | Digit character: 0 to 9 | | ||
| `whitespace` | `\s` | Whitespace character: space, tab, line break, ... | | ||
| `anyOf('abc')` | `[abc]` | Any of provided characters | | ||
| `charRange('a', 'z')` | `[a-z]` | Character in a range | | ||
| `charClass(...)` | `[...]` | Union of multiple character classes | | ||
| `negated(...)` | `[^...]` | Negation of a given character class | | ||
| `char(...)` | `\uXXXX` | Character specified given Unicode code point | | ||
| `unicodeProperty(...)` | `\p{...}` | Characters with given Unicode property | | ||
See [Character Classes API doc](https://callstack.github.io/ts-regex-builder/api/character-classes) and [Unicode API doc](https://callstack.github.io/ts-regex-builder/api/unicode) for more info. | ||
### Assertions | ||
@@ -157,3 +139,3 @@ | ||
| `lookahead(...)` | `(?=...)` | Match subsequent text without consuming it | | ||
| `negativeLookhead(...)` | `(?!...)` | Reject subsequent text without consuming it | | ||
| `negativeLookahead(...)` | `(?!...)` | Reject subsequent text without consuming it | | ||
| `lookbehind(...)` | `(?<=...)` | Match preceding text without consuming it | | ||
@@ -164,2 +146,20 @@ | `negativeLookbehind(...)` | `(?<!...)` | Reject preceding text without consuming it | | ||
### Character classes | ||
> [!TIP] | ||
> You may also use inline regexes for specifying character classes, as they offer a concise yet readable syntax. For example, `/[a-z0-9_]/`. | ||
| Character class | Regex Syntax | Description | | ||
| --------------------- | ------------ | ------------------------------------------------- | | ||
| `any` | `.` | Any character | | ||
| `word` | `\w` | Word character: letter, digit, underscore | | ||
| `digit` | `\d` | Digit character: 0 to 9 | | ||
| `whitespace` | `\s` | Whitespace character: space, tab, line break, ... | | ||
| `anyOf('abc')` | `[abc]` | Any of provided characters | | ||
| `charRange('a', 'z')` | `[a-z]` | Character in a range | | ||
| `charClass(...)` | `[...]` | Union of multiple character classes | | ||
| `negated(...)` | `[^...]` | Negation of a given character class | | ||
See [Character Classes API doc](https://callstack.github.io/ts-regex-builder/api/character-classes) and [Unicode API doc](https://callstack.github.io/ts-regex-builder/api/unicode) for more info. | ||
## Examples | ||
@@ -193,6 +193,4 @@ | ||
--- | ||
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
142390
103
1412
0
191