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

  • Home
  • SEARCH
  • 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 693457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:45:21+00:00 2026-05-14T02:45:21+00:00

I have a textbox where a user puts a string like this: hello world!

  • 0

I have a textbox where a user puts a string like this:

"hello world! I think that __i__ am awesome (yes I am!)"

I need to create a correct URL like this:

hello-world-i-think-that-i-am-awesome-yes-i-am

How can it be done using regular expressions?

Also, is it possible to do it with Greek (for example)?

"Γεια σου κόσμε"

turns to

geia-sou-kosme

In other programming languages (Python/Ruby) I am using a translation array. Should I do the same here?

  • 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-05-14T02:45:21+00:00Added an answer on May 14, 2026 at 2:45 am

    Try this:

    function doDashes(str) {
        var re = /[^a-z0-9]+/gi; // global and case insensitive matching of non-char/non-numeric
        var re2 = /^-*|-*$/g;     // get rid of any leading/trailing dashes
        str = str.replace(re, '-');  // perform the 1st regexp
        return str.replace(re2, '').toLowerCase(); // ..aaand the second + return lowercased result
    }
    console.log(doDashes("hello world! I think that __i__ am awesome (yes I am!)"));
    // => hello-world-I-think-that-i-am-awesome-yes-I-am
    

    As for the greek characters, yeah I can’t think of anything else than some sort of lookup table used by another regexp.

    Edit, here’s the oneliner version:
    Edit, added toLowerCase():
    Edit, embarrassing fix to the trailing regexp:

    function doDashes2(str) {
        return str.replace(/[^a-z0-9]+/gi, '-').replace(/^-*|-*$/g, '').toLowerCase();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here i have a textbox in which user inputs html tags like <h1>hello</h1> then
I have a textbox where a user inputs a number, like: 105.14 When I
I have a TextBox in a Windows Form that allows a user to enter
I'm writing a WPF calculator app. In this application I have TextBox that get
I have a textbox.T he user will be entering entering a number in this
I have a TextBox that user can enter search-term in it. Its bind to
I have a textbox where the user enters a random string. I want to
here's my problem. I have this piece of code that sets the user location
I have a textbox that the user can input into. Right now the user
In my website I have a textbox that allow user to enter a group

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.