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

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

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 Report

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 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!