Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

288
Vistas
RegExp in JavaScript: include one Unicode group and exclude another one

I have to write some regexp. And I know where is a lot of variants. But I find the thing that I don't understand, so I want to ask.

I had this regexp: /^[\p{Letter} \-'`’–]+$/u It has to allow Latin and symbols like Ü, Æ ect.

And it has bug - it allows also Ukrainian (Cyrillic) symbols "і Ї". So I want to add the rule "exclude Cyrillic". But I don't know how to do it.

I tried /^[\p{Letter} \-'`’–][^\p{sc=Cyrillic}]+$/u; but the last part [^] means all except Cyrillic ((

Please, don't say me to rewrite regexp. I just want to learn how can I write "exclude" rule.

Thanks)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In your /^[\p{Letter} \-'`’–]+$/u regex, \p{Letter} matches any letter in the Unicode table. However, \p{Alphabetic} includes more letters, and you would like to use this Unicode category class if you planned to match any Unicode letter.

Since you only want to match Latin letters you should replace \p{Letter} with \p{sc=Latin} or \p{sc=Latn} (note the hyphen should be just used at the end of the character class, it is the cleanest way to use it here).

Note that the sc=, or Script= (this is for Script names, scx= or Script_Extensions= can be used for script extensions) prefix is required to work with those script names in Unicode category classes (see ECMAScript reference).

See a JavaScript demo:

const rx = /^[\p{sc=Latn} '`’–-]+$/u;
console.log( rx.test("Вася-Пупкин’о") ); // => false
console.log( rx.test("Łukasz Ąłski") );  // => true
console.log( rx.test("Chloé Alméras") ); // => true

If you wanted to match any letters but Cyrillic ones, you would need to only add a negative lookahead like this:

const rx = /^(?:(?!\p{sc=Cyrl})[\p{Alphabetic} '`’–-])+$/u;
console.log( rx.test("Вася-Пупкин’о") ); // => false
console.log( rx.test("עֲדִינָה") );         // => true
console.log( rx.test("Łukasz Ąłski") );  // => true
console.log( rx.test("Chloé Alméras") ); // => true

See more about value aliases and canonical values for the Unicode properties (Script and Script_Extensions) here.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda