Skip to content

Instantly share code, notes, and snippets.

@AmyShackles
Created July 27, 2021 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmyShackles/cd26cf6930fdd1563143e1f045a1c084 to your computer and use it in GitHub Desktop.
Save AmyShackles/cd26cf6930fdd1563143e1f045a1c084 to your computer and use it in GitHub Desktop.
const desiredOutput = [
{
type: 'start_of_line',
startingIndex: 0,
lastIndex: 0,
group: '^',
children: [],
},
{
type: 'positive_lookbehind',
group: '(?<=Hello (a(ga)in))',
match: 'Hello (a(ga)in)',
startingIndex: 1,
lastIndex: 20,
children: [
{
type: 'literal',
startingIndex: 5,
lastIndex: 10,
group: 'Hello ',
children: [],
},
{
type: 'capture_group',
group: '(a(ga)in)',
match: 'a(ga)in',
startingIndex: 11,
lastIndex: 19,
children: [
{
type: 'literal',
startingIndex: 12,
lastIndex: 12,
group: 'a',
children: []
},
{
type: 'capture_group',
group: '(ga)',
match: 'ga',
startingIndex: 13,
lastIndex: 16,
children: [
{
type: 'literal',
startingIndex: 14,
lastIndex: 15,
group: 'ga',
children: []
}
]
},
{
type: 'literal',
startingIndex: 17,
lastIndex: 18,
group: 'in',
children: []
}
]
}
]
},
{
type: 'word_boundary',
startingIndex: 21,
lastIndex: 22,
group: '\\b',
children: []
},
{
type: 'capture_group',
group: '(ABC)',
match: 'ABC',
startingIndex: 23,
lastIndex: 27,
children: [
{
type: 'literal',
startingIndex: 24,
lastIndex: 26,
group: 'ABC'
},
]
},
{
type: 'negated_character_set',
startingIndex: 28,
lastIndex: 33,
group: '[^ack]',
match: 'ack',
children: []
},
{
type: 'dotAll',
startingIndex: 34,
lastIndex: 34,
group: '.',
children: []
},
{
type: 'non_greedy_range_quantifier',
startingIndex: 35,
lastIndex: 38,
group: '{2}?',
min: 2,
children: []
},
{
type: 'capture_group',
group: '(\\P{Script=Cyrillic} \\p{General_Category=Letter}\\xff \\u{12345})',
match: '\\P{Script=Cyrillic} \\p{General_Category=Letter}\\xff \\u{12345}',
startingIndex: 39,
lastIndex: 101,
children: [
{
type: 'negated_unicode_property_escape',
startingIndex: 40,
lastIndex: 58,
negated_unicode_name: 'Script',
negated_unicode_value: 'Cyrillic',
group: '\\P{Script=Cyrillic}',
children: []
},
{
type: 'literal',
startingIndex: 59,
lastIndex: 59,
group: ' ',
children: []
},
{
type: 'unicode_property_escape',
startingIndex: 60,
lastIndex: 86,
unicode_name: 'General_Category',
unicode_value: 'Letter',
group: '\\p{General_Category=Letter}',
children: []
},
{
type: 'hex',
startingIndex: 87,
lastIndex: 90,
group: '\\xff',
match: 'ÿ',
children: []
},
{
type: 'literal',
startingIndex: 91,
lastIndex: 91,
group: ' ',
children: []
},
{
type: 'unicode',
startingIndex: 92,
lastIndex: 100,
group: '\\u{12345}',
match: '𒍅',
children: []
},
]
},
{
type: 'named_capture_group',
group: '(?<isas>[ai]s)',
match: '[ai]s',
startingIndex: 102,
lastIndex: 115,
name: 'isas',
children: [
{
type: 'character_set',
startingIndex: 110,
lastIndex: 113,
group: '[ai]',
match: 'ai',
children: []
},
{
type: 'literal',
startingIndex: 114,
lastIndex: 114,
group: 's',
children: []
},
]
},
{
type: 'whitespace',
startingIndex: 116,
lastIndex: 117,
group: '\\s',
children: []
},
{
type: 'character_set',
startingIndex: 118,
lastIndex: 123,
group: '[easy]',
match: 'easy',
children: []
},
{
type: 'greedy_range_quantifier',
startingIndex: 124,
lastIndex: 128,
group: '{1,5}',
min: 1,
max: 5,
children: []
},
{
type: 'literal',
startingIndex: 129,
lastIndex: 129,
group: ' ',
children: []
},
{
type: 'unicode_property_escape',
startingIndex: 130,
lastIndex: 145,
unicode_name: 'Script',
unicode_value: 'Latin',
group: '\\p{Script=Latin}',
children: []
},
{
type: 'named_backreference',
startingIndex: 146,
lastIndex: 153,
group: '\\k<isas>',
name: 'isas',
children: []
},
{
type: 'whitespace',
startingIndex: 154,
lastIndex: 155,
group: '\\s',
children: []
},
{
type: 'capture_group',
group: '(123)',
match: '123',
startingIndex: 156,
lastIndex: 160,
children: [
{
type: 'literal',
startingIndex: 157,
lastIndex: 159,
group: '123',
children: []
},
]
},
{
type: 'numerical_backreference',
startingIndex: 161,
lastIndex: 162,
group: '\\1',
match: '1',
children: []
},
{
type: 'numerical_backreference',
startingIndex: 163,
lastIndex: 164,
group: '\\2',
match: '2',
children: []
},
{
type: 'greedy_range_quantifier',
startingIndex: 165,
lastIndex: 167,
group: '{3}',
min: 3,
children: []
},
{
type: 'unicode',
startingIndex: 168,
lastIndex: 173,
group: '\\u1234',
match: 'ሴ',
children: []
},
{
type: 'literal',
startingIndex: 174,
lastIndex: 174,
group: ' ',
children: []
},
{
type: 'character_set',
startingIndex: 175,
lastIndex: 178,
group: '[\\b]',
match: '\\b',
children: [
{
type: 'backspace',
startingIndex: 176,
lastIndex: 177,
group: '\\b',
children: []
},
]
},
{
type: 'literal',
startingIndex: 179,
lastIndex: 187,
group: 'sometimes',
children: []
},
{
type: 'control_character',
startingIndex: 188,
lastIndex: 190,
group: '\\cM',
match: '\r',
children: []
},
{
type: 'non_word_boundary',
startingIndex: 191,
lastIndex: 192,
group: '\\B',
children: []
},
{
type: 'positive_lookahead',
group: '(?=Goodbye)',
match: 'Goodbye',
startingIndex: 193,
lastIndex: 203,
children: [
{
type: 'literal',
startingIndex: 196,
lastIndex: 202,
group: 'Goodbye'
},
]
},
{
type: 'end_of_line',
startingIndex: 204,
lastIndex: 204,
group: '$',
children: []
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment