RegionMatchers
regionMatch
Section titled “regionMatch”Compares two strings or regions for equality.
Parameters
Section titled “Parameters”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.
Returns: boolean
Section titled “Returns: boolean”- True if the strings or regions match, false otherwise.
function regionMatch( str1: StringRegion | string, str2: StringRegion | string, start?: number, end?: number): boolean// Matching identical stringsregionMatch('hello', 'hello') // true
// Matching identical regions in stringsconst str1 = { str: 'hello world', start: 0, end: 5 }const str2 = { str: 'hello there', start: 0, end: 5 }regionMatch(str1, str2) // true// ORregionMatch('hello world', 'hello there', 0, 5) // true
// Not matching regionsregionMatch('hello world', 'hello there', 6, 11) // false
// Matching regions with different ending pointsconst str5 = { str: ' hello world', start: 1, end: 6 };const str6 = { str: 'hello there', start: 0, end: 5 };regionMatch(str5, str6); // truelooseRegionMatch
Section titled “looseRegionMatch”Performs a loose comparison of two strings or regions for equality.
Parameters
Section titled “Parameters”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.
Returns: boolean
Section titled “Returns: boolean”- True if the strings or regions match loosely, false otherwise.
function looseRegionMatch( str1: StringRegion | string, str2: StringRegion | string, start?: number, end?: number): boolean// Loose matching identical stringslooseRegionMatch('hello', 'HeLLo') // true
// Loose matching identical regions in stringsconst str1 = { str: ' hellO world', start: 1, end: 6 }const str2 = { str: 'HelLo there', start: 0, end: 5 }looseRegionMatch(str1, str2) // true