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

256
Visualizações
How to get uppercase words in sentence using javascript

I am trying to get special words from script to search it in Wikipedia to get explanation.

Input text: "Thai, or Central Thai, is a Tai language of the Kra–Dai language family spoken by the Central Thai people and a vast majority of Thai Chinese. It is the sole official language of Thailand. I want to... "

The expect ouput: ["Thai", "Central Thai", "Kra–Dai", "Thai Chinese", "Thailand"]

Then by uing the Wikipedia API I will get the definitions of the words above. I am using this regular expression:

[A-Z][-a-zA-Z]*(?:\s+[A-Z][-a-zA-Z]*)?

However when I try the result is:

["Thai", "Central Thai", "Kra", "Dai", "Thai Chinese", "Thailand", "I", "It"]

It is separating the words with that contains "-" and including the ones that start with upper after a dot "." and also is including "I" and "It".

How could I get all uppercase words except the uppercase word after "."

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

0

We can use word boundaries \b.

let str = 'Thai, or Central Thai, is a Tai language of the Kra-Dai language family spoken by the Central Thai people and a vast majority of Thai Chinese. It is the sole official language of Thailand. I want to...';
let arr =[...str.matchAll( /\b[A-Z]\w{2,}-?(\s?\b[A-Z]\w*)?/g)].map(e=>e[0]);
console.log(arr);

How could I get all uppercase words except the uppercase word after "."

But you can get special words at the start of a sentence too:
Periplectic group consists of the group's last common ancestor and all its descendants

about 4 years ago · Juan Pablo Isaza Relatório

0

This worked for me (?!.\s)[A-Z][a-z]+(?:\s[A-Z][a-z]+|[–]+[A-Z][a-z]*|[a-z]+)

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