A lightweight JavaScript library that helps structure regex quickly and easily. This library does not replace learning regex but assists in their usage by removing the concrete implementation of regex and focus on results instead.
Installation:
npm install regex-helper-ease
Find the complete documentation here.
const regex = new RegexHelper()
.query({
// pre build regex (dd/mm/yyyy)
regex: `${EUFullDate}`,
// the name of your regex
name: 'fullDate',
// text to display if no value has been found
valueIfNotFound: 'Date not found',
})
.query({
regex: `(?:service|article) :? (${anyDigits})`,
name: 'articleOrService',
// this will capture the value of the first group (index: 1)
capturingGroup: [{ name: 'articleNumber', index: 1 }],
})
.query({
regex: `has been paid`,
name: 'isPaid',
// test only for presence (returns a boolean string, "true" | "false")
test: true,
})
// the text where to perform searching
.findIn('The article: 471 has been paid on 12/12/2022.')
// can be: 'data' | 'debug' | 'general'
.get('data');
The regex displays following results:
{
fullDate: '12/12/2022',
articleOrService: 'article: 471',
articleNumber: '471',
isPaid: 'true'
}
This library comes with a serie of pre build regex. Special attention has been given on developer experience. Properties and methods are exhaustively documented and typed. Use your IDE's autocompletion or hover on properties and methods for help. Errors (see 'pitfalls' here) will be logged in console with explicit messages.
Feel free! Open a ticket.
V0.0.2: [MINOR] Improved typescript return type of the results.
V0.0.3: [MINOR] Escaping empty regex at initialisation and adding a general success rate in percentage in the General interface. Bug corrections and adding tests.
V0.0.4: [MINOR] Adding fuzzy search possibility and tests.
All libraries are permanently supported. Discover them here.