Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

285
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!