Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

160
Visualizações
How to combine multiple Unicode character properties in JavaScript?

There are \p{Script=Latin} (also can be written as \p{sc=Latin}) and \p{Uppercase}.

But there is currently no way to select an intersection of multiple sets like /^([ \p{Script=Latin} & \p{Uppercase} ])/ in Perl ≥5.18 or \p{Script=Latin,Uppercase}.

So the task is to find a workaround.

Example input:

const input = [
'License: GPL!',
'License: WÐFPL!',
'License: None!',
]

Example output: ['GPL', 'WÐFPL']

The answer could use use a regexp that looks like this for example: /^License:\s*(?<abbr>\p{Script=Latin,Uppercase}+)!$/u

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

There's no ideal workaround to do that except if you want the intersection of predefined character classes. All you have to do is to use a negation and negated character classes:

/^License:\s*([^\P{Script=Latin}\P{Uppercase}]+)!/u

demo

It is simple set logic:

A ∩ B = ∁∁(A ∩ B)    // complement of a complement is an involution
A ∩ B = ∁(∁A ∪ ∁B)   // Morgan's law: complement of an intersection is the union
                     // of complements
about 4 years ago · Juan Pablo Isaza Relatório

0

const input = [
'License: GPL!',
'License: WÐFPL!',
'License: None!',
]
const regexp = /^License:\s*(?<abbr>(?:(?![ƗØ])(?=\p{Uppercase})\p{sc=Latin})+)!$/u
console.log(input.map(str => str.match(regexp)?.groups?.abbr).filter(Boolean))

Explanation:

^
License:
\s*
(?<abbr>   // named capture groups
    (?:
        // A negative look-ahead assertion.
        // Exclusion of Ɨ and Ø was not required by the question;
        // this line is here to provide more examples.
        (?![ƗØ])

        // A look-ahead assertion (looks into the future,
        // and then always goes back to the former position)
        (?=\p{Uppercase})

        \p{sc=Latin}
    )+
)
!
$
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda