Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:24:24+00:00 2026-06-07T17:24:24+00:00

I need to -automatically- generate tags for a text string. In this case, I’ll

  • 0

I need to -automatically- generate tags for a text string. In this case, I’ll use this string:

var text = 'This text talks about loyalty in the Royal Family with Príncipe Charles';

My current implementation, generates the tags for words that are 6+ characters long, and it works fine.

words = (text).replace(/[^a-zA-Z\s]/g,function(str){return '';});
words = words.match(/\w{6,}/g);
console.log(words);

This will return:

["loyalty","Family","Prince","Charles"]

The problem is that sometimes, a tag should be a specific set of words. I need the result to be:

["loyalty","Royal Family","Príncipe Charles"]

That means, that the replace/match code should test for:

  1. words that are 6 characters long (or more); and/or
  2. if a set of words starts with an uppercase letter, those words should be joined together in the same array element. It doesn’t matter if some of the words are less than 6 characters long – but at least one of them has to be 6+, e.g.: “Stop at The UK Guardián in London” should return [“The UK Guardián”, “London”]

I’m obviously having trouble in the second requirement. Any ideas? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:24:26+00:00Added an answer on June 7, 2026 at 5:24 pm
    var text = 'This text talks about loyalty in the Royal Family with Prince Charles. Stop at The UK Guardian in London';
    
    text.match(/(([A-Z]\w*\s*){2,})|(\w{6,})/g)
    

    will return

    ["loyalty", "Royal Family ", "Prince Charles", "The UK Guardian ", "London"]
    

    To fulfill the second requirement, it’s better to run another regexp over the matches found:

    var text = 'This is a Short Set Of Words about the Royal Family'
    
    matches = text.match(/(([A-Z]\w*\s*){2,})|(\w{6,})/g)
    matches.filter(function(m) {
        return m.match(/\w{6,}/)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate multiple databases to SQL, so I need script/program to automatically
I need to generate windows form fields based off of a text file that
I'm writing a program for Employees Management and i need to automatically generate a
I am trying to use PHP and MySQL to automatically generate a list like
I need a way to automatically generate a thumbnail of the target page when
I have some automatically generated Ant build scripts that I need to use to
I need to generate the following XML: <Learner xmlns=some.domain.api> <ActivationDate>1999-05-31T11:20:00</ActivationDate> <EmailAddress>String content</EmailAddress> <ExpirationDate>1999-05-31T11:20:00</ExpirationDate> <FederalId>String
I need to automatically generate a PDF file from an exisiting (X)HTML-document. The input
I want to use SEQUENCE strategy for automatically generate ids, but i am breaking
I'd like to use the ImageMagick convert tool to automatically generate a toolbar bitmap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.