By default,Documentation Index
Fetch the complete documentation index at: https://mintlify.com/angezid/advanced-mark.js/llms.txt
Use this file to discover all available pages before exploring further.
markRegExp() highlights the entire string matched by a regular expression. Enabling separateGroups: true changes this behaviour — instead of wrapping the whole match, the library wraps each capturing group individually. This lets you apply different styles to different parts of a pattern, skip specific groups entirely, or count groups separately.
Basic usage
PassseparateGroups: true alongside a regex that has both the g and d flags. Each capturing group in the pattern is treated as an independent highlight target:
separateGroups with element and className as usual, or use the each callback to assign per-group classes (see Counting groups below).
Filtering specific groups
Useinfo.groupIndex inside the filter callback to include or exclude individual groups. groupIndex is the 1-based index of the group currently being considered for wrapping.
When a match spans multiple elements (
acrossElements: true), info.groupIndex remains the same for every text-node call made while wrapping that group. Use it safely as a stable identifier across node boundaries.Filtering a whole match based on group content
You can inspectinfo.match — the raw RegExp.exec() result — to make filtering decisions based on whether a particular group matched at all:
Group highlighting with acrossElements
WhenacrossElements: true is combined with separateGroups: true, use the each callback’s info.groupStart property to detect when a new group begins — this is the right place to assign per-group classes or update per-group counters:
info.groupStart fires exactly once per group per match, even if the group spans several text nodes. It is only available when both acrossElements: true and separateGroups: true are active.
Counting groups
WithoutacrossElements, every each call corresponds to exactly one mark element for one group. Use info.groupIndex to maintain per-group counters:
Nesting rule
The library applies a nesting rule whenwrapAllRanges is not enabled:
- Without
wrapAllRanges— if a parent group has already been wrapped, all groups nested inside it are ignored. To highlight a nested group, you must filter out the parent group infilterso it is skipped, allowing the nested group to be processed. - With
wrapAllRanges: true— parent and nested groups are all wrapped independently. Usefilteroreachto remove any groups you don’t need.
See Nesting & Overlapping for full details on using
wrapAllRanges to highlight capturing groups at any nesting depth, including groups inside lookaround assertions.