Skip to main content

Constant

const MARKER_ID_PATTERN: string;

Value

// Pattern matches: [BFTNCP]\d+[a-z]?
// Examples: P1234, B45a, H890, F123b

Description

A regular expression pattern string that matches valid segment IDs used in Islamic text translations. The pattern is constructed from TRANSLATION_MARKER_PARTS and matches:
  • A single letter prefix (marker type)
  • One or more digits
  • An optional lowercase letter suffix

Valid marker prefixes

PrefixTypeExample
BBookB123
FFootnoteF45a
THeadingT890
CChapterC567
NNoteN234b
PPlain segmentP1234

Usage

Validate segment ID format

import { MARKER_ID_PATTERN } from 'wobble-bibble';

const pattern = new RegExp(`^${MARKER_ID_PATTERN}$`);

pattern.test('P1234');   // true
pattern.test('B45a');    // true
pattern.test('H890');    // true
pattern.test('123');     // false (no prefix)
pattern.test('X123');    // false (invalid prefix)
pattern.test('P123A');   // false (uppercase suffix)

Extract IDs from text

import { MARKER_ID_PATTERN } from 'wobble-bibble';

const text = 'P1234 - Translation here\nB45a - Another translation';
const pattern = new RegExp(MARKER_ID_PATTERN, 'g');
const ids = [...text.matchAll(pattern)].map(m => m[0]);

console.log(ids);  // ['P1234', 'B45a']

Build marker pattern

import { MARKER_ID_PATTERN, TRANSLATION_MARKER_PARTS } from 'wobble-bibble';

const { dashes, optionalSpace } = TRANSLATION_MARKER_PARTS;

// Match "ID - Text" format
const markerPattern = new RegExp(
  `^(${MARKER_ID_PATTERN})${optionalSpace}${dashes}\\s*`,
  'gm'
);

const text = 'P1234 - Translation text';
const match = text.match(markerPattern);
console.log(match);  // ['P1234 - ']

Pattern construction

The pattern is built from TRANSLATION_MARKER_PARTS:
// From constants.ts
const MARKER_ID_PATTERN = 
  `${TRANSLATION_MARKER_PARTS.markers}` +      // [BFTNCP]
  `${TRANSLATION_MARKER_PARTS.digits}` +       // \d+
  `${TRANSLATION_MARKER_PARTS.suffix}?`;       // [a-z]?

Use cases

Internal validation

The library uses this pattern internally in:
  • validateTranslationResponse() - Validate marker format
  • extractTranslationIds() - Extract IDs from text
  • parseTranslations() - Parse ID-translation pairs

Custom validation

import { MARKER_ID_PATTERN } from 'wobble-bibble';

function validateSegmentId(id: string): boolean {
  const pattern = new RegExp(`^${MARKER_ID_PATTERN}$`);
  return pattern.test(id);
}

console.log(validateSegmentId('P1234'));   // true
console.log(validateSegmentId('INVALID')); // false

Custom parsing

import { MARKER_ID_PATTERN } from 'wobble-bibble';

function extractMarkerType(id: string): string | null {
  const pattern = new RegExp(`^([BFTNCP])`);
  const match = id.match(pattern);
  return match ? match[1] : null;
}

console.log(extractMarkerType('P1234'));  // 'P'
console.log(extractMarkerType('B45a'));   // 'B'

Build docs developers (and LLMs) love