All Projects → pocesar → js-diacritic-regex

pocesar / js-diacritic-regex

Licence: MIT license
Creates the inverse of transliterated string to a regex. What? Basically, diacritic insensitiveness

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to js-diacritic-regex

ethereum-regex
Ξ Regular expression for matching Ethereum (ETH) addresses.
Stars: ✭ 19 (-5%)
Mutual labels:  regex, regex-match
regexp-example
正则表达式实例搜集,通过实例来学习正则表达式。
Stars: ✭ 162 (+710%)
Mutual labels:  regex, regexp
moar
Deterministic Regular Expressions with Backreferences
Stars: ✭ 19 (-5%)
Mutual labels:  regex, regexp
cryptaddress.now
A minimal service to detect which cryptocurrency an address corresponds to.
Stars: ✭ 23 (+15%)
Mutual labels:  regex, regex-match
regexp-expand
Show the ELisp regular expression at point in rx form.
Stars: ✭ 18 (-10%)
Mutual labels:  regex, regexp
Regex For Regular Folk
🔍💪 Regular Expressions for Regular Folk — A visual, example-based introduction to RegEx [BETA]
Stars: ✭ 242 (+1110%)
Mutual labels:  regex, regexp
Regaxor
A regular expression fuzzer.
Stars: ✭ 35 (+75%)
Mutual labels:  regex, regexp
Common Regex
🎃 常用正则表达式 - 收集一些在平时项目开发中经常用到的正则表达式。
Stars: ✭ 2,488 (+12340%)
Mutual labels:  regex, regexp
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Stars: ✭ 26 (+30%)
Mutual labels:  regex, regexp
cregex
A small implementation of regular expression matching engine in C
Stars: ✭ 72 (+260%)
Mutual labels:  regex, regexp
Stringi
THE String Processing Package for R (with ICU)
Stars: ✭ 204 (+920%)
Mutual labels:  regex, regexp
regXwild
⏱ Superfast ^Advanced wildcards++? | Unique algorithms that was implemented on native unmanaged C++ but easily accessible in .NET via Conari (with caching of 0x29 opcodes +optimizations) etc.
Stars: ✭ 20 (+0%)
Mutual labels:  regex, regexp
Regex Automata
A low level regular expression library that uses deterministic finite automata.
Stars: ✭ 203 (+915%)
Mutual labels:  regex, regexp
is-regex
Is this value a JS regex?
Stars: ✭ 22 (+10%)
Mutual labels:  regex, regexp
Regexpu
A source code transpiler that enables the use of ES2015 Unicode regular expressions in ES5.
Stars: ✭ 201 (+905%)
Mutual labels:  regex, regexp
transliteration-php
🇺🇦 🇬🇧 🔡 🐘 PHP library for transliteration.
Stars: ✭ 34 (+70%)
Mutual labels:  transliteration, transliterate
Grex
A command-line tool and library for generating regular expressions from user-provided test cases
Stars: ✭ 4,847 (+24135%)
Mutual labels:  regex, regexp
Regex Benchmark
It's just a simple regex benchmark of different programming languages.
Stars: ✭ 171 (+755%)
Mutual labels:  regex, regexp
url-regex-safe
Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
Stars: ✭ 59 (+195%)
Mutual labels:  regex, regexp
IronRure
.NET Bindings to the Rust Regex Crate
Stars: ✭ 16 (-20%)
Mutual labels:  regex, regexp

Build Status Coverage Status

NPM

Diacritic regex

Creates the inverse of transliterated string to a regex. What? Basically, a regex that is diacritic insensitive

Why?

Sometimes the user will search for blasé, but your database is dumb and doesn't understand collations and diacritic insensitiveness, but it can compare stuff using regex, so there ya go.

How?

Suppose you have the word résumé but written improperly in the database as resume. The user is clever, and types it correctly into the search box. Gets nothing. How to search for all the weird cases people mistype stuff when comes to accents?

import { toRegex, toString } from 'diacritic-regex';

toRegex()('résumé') // => /r[eEÉéÈèÊêëË]s[úùÚÙüÜuU]m[eEÉéÈèÊêëË]/i;
toRegex({flags: 'mu'})('résumé') // => /r[eEÉéÈèÊêëË]s[úùÚÙüÜuU]m[eEÉéÈèÊêëË]/mu;
toRegex({
  flags: '',
  mappings: {
    'e': 'eéÉ'
  }
})('résumé') // => /r[eéÉ]s[úùÚÙüÜuU]m[eéÉ]/;

toString({
    mappings: {
        '*': ['\\S+'] // literals, won't try to wrap in []'s,
        'u': ['u']
    }
})('résumé*') // => 'r[eEÉéÈèÊêëË]sum[eEÉéÈèÊêëË]\S+'

If you want to change the mappings for all instances:

import { mappings } from 'diacritic-regex'

mappings['*'] = ['[\\S\\s]+']

Caveats

Be aware of RegExp.prototype.exec with g flag being stateful

The i flag is appended to the RegExp flags if you don't pass any flags to toRegex

Compatibility

Work in node and the browser, but needs polyfills for Array.reduce, Array.map and Object.keys depending on how old your target browser is

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].