Skip to content

Commit

Permalink
update reg to be international
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-hub committed Sep 14, 2024
1 parent e922863 commit dac760c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
77 changes: 77 additions & 0 deletions src/utils/reg.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { BOOK_REG, MODAL_REG } from './regs'

describe('test book name reg matching in different languages', () => {
test('should match book name in English', () => {
const bookName = 'John'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should match book name in Italian', () => {
const bookName = 'Giovanni'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should match book name in Japanese', () => {
const bookName = 'ヨハネ'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should match book name in Spanish', () => {
const bookName = 'Juan'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should match book name in Chinese', () => {
const bookName = '约翰福音'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should match book name in French', () => {
const bookName = 'Josué'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should not cover just one letter', () => {
const bookName = 'J'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(false)
})
})

describe('test modal reg matching in different languages', () => {
test('should match modal in English', () => {
const modal = 'John 1:1'
const reg = new RegExp(MODAL_REG)
expect(reg.test(modal)).toBe(true)
})

test('should match modal in English Withou Space', () => {
const modal = 'John1:1'
const reg = new RegExp(MODAL_REG)
expect(reg.test(modal)).toBe(true)
})

test('should match book name in French', () => {
const bookName = 'Josué1:1'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should match book name in Chinese', () => {
const bookName = '约翰福音2:1'
const reg = new RegExp(BOOK_REG)
expect(reg.test(bookName)).toBe(true)
})

test('should not match if use letter for number', () => {
const modal = 'John a:1'
const reg = new RegExp(MODAL_REG)
expect(reg.test(modal)).toBe(false)
})
})
10 changes: 7 additions & 3 deletions src/utils/regs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
* John1:1
* 1John1:1
*/
export const MODAL_REG =
/([123])*\s*[A-Z\[\\\]^_`a-z]{2,}\s*\d{1,3}:\d{1,3}(-\d{1,3})*/
// export const MODAL_REG =
// /([123])*\s*[A-Z\[\\\]^_`a-z]{2,}\s*\d{1,3}:\d{1,3}(-\d{1,3})*/

export const BOOK_REG = /[123]*\s*[A-Z\[\\\]^_`a-z]{2,}/
export const MODAL_REG = /([123])*\s*([\p{L}[\\\]^_`a-zA-Z]{2,100}|\p{Script=Han}{1,})\s*\d{1,3}:\d{1,3}(-\d{1,3})*/isu

export const BOOK_REG = /([123])*\s*([\p{L}[\\\]^_`a-zA-Z]{2,100}|\p{Script=Han}{1,})/isu

// export const BOOK_REG = /[123]*\s*[A-Z\[\\\]^_`a-z]{2,}/

/**
* prefix of the trigger
Expand Down

0 comments on commit dac760c

Please sign in to comment.