Skip to content

RegionMatchers

Compares two strings or regions for equality.

  • str1: StringRegion | string - The first string or region to compare.
  • str2: StringRegion | string - The second string or region to compare.
  • start?: number - The starting index of the region in the first string.
  • end?: number - The ending index of the region in the first string.
  • True if the strings or regions match, false otherwise.
Definition
function regionMatch(
str1: StringRegion | string,
str2: StringRegion | string,
start?: number,
end?: number): boolean
Examples
// Matching identical strings
regionMatch('hello', 'hello') // true
// Matching identical regions in strings
const str1 = { str: 'hello world', start: 0, end: 5 }
const str2 = { str: 'hello there', start: 0, end: 5 }
regionMatch(str1, str2) // true
// OR
regionMatch('hello world', 'hello there', 0, 5) // true
// Not matching regions
regionMatch('hello world', 'hello there', 6, 11) // false
// Matching regions with different ending points
const str5 = { str: ' hello world', start: 1, end: 6 };
const str6 = { str: 'hello there', start: 0, end: 5 };
regionMatch(str5, str6); // true

Performs a loose comparison of two strings or regions for equality.

  • str1: StringRegion | string - The first string or region to compare.
  • str2: StringRegion | string - The second string or region to compare.
  • start?: number - The starting index of the region in the first string.
  • end?: number - The ending index of the region in the first string.
  • True if the strings or regions match loosely, false otherwise.
Definition
function looseRegionMatch(
str1: StringRegion | string,
str2: StringRegion | string,
start?: number,
end?: number): boolean
Examples
// Loose matching identical strings
looseRegionMatch('hello', 'HeLLo') // true
// Loose matching identical regions in strings
const str1 = { str: ' hellO world', start: 1, end: 6 }
const str2 = { str: 'HelLo there', start: 0, end: 5 }
looseRegionMatch(str1, str2) // true