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 6944495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:18:51+00:00 2026-05-27T13:18:51+00:00

Looking for a regex/replace function to take a user inputted string say, John Smith’s

  • 0

Looking for a regex/replace function to take a user inputted string say, “John Smith’s Cool Page” and return a filename/url safe string like “john_smith_s_cool_page.html”, or something to that extent.

  • 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-27T13:18:52+00:00Added an answer on May 27, 2026 at 1:18 pm

    Well, here’s one that replaces anything that’s not a letter or a number, and makes it all lower case, like your example.

    var s = "John Smith's Cool Page";
    var filename = s.replace(/[^a-z0-9]/gi, '_').toLowerCase();
    

    Explanation:

    The regular expression is /[^a-z0-9]/gi. Well, actually the gi at the end is just a set of options that are used when the expression is used.

    • i means "ignore upper/lower case differences"
    • g means "global", which really means that every match should be replaced, not just the first one.

    So what we’re looking as is really just [^a-z0-9]. Let’s read it step-by-step:

    • The [ and ] define a "character class", which is a list of single-characters. If you’d write [one], then that would match either ‘o’ or ‘n’ or ‘e’.
    • However, there’s a ^ at the start of the list of characters. That means it should match only characters not in the list.
    • Finally, the list of characters is a-z0-9. Read this as "a through z and 0 through 9". It’s a short way of writing abcdefghijklmnopqrstuvwxyz0123456789.

    So basically, what the regular expression says is: "Find every letter that is not between ‘a’ and ‘z’ or between ‘0’ and ‘9’".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to make the search/replace function of VS IDE regex-aware,
I am looking for a regex that will match a string that starts with
I am looking for a regex to validate a string. I want to allow
I’m looking for a way to go through a string and replace all instances
I am looking for a regex to replace all terms in parentheses unless the
Assume I have the string: 10,11,12,13,14,ABC,DEF,GHI,66 I am looking to run a regex against
I am looking for a in-built String split function in Hive? e.g. if String
I'm looking for a greedy RegEx match to replace all text in a number
I'm looking for a regex that will allow me to validate whether or not
I am looking for a regex that will find repeating letters. So any letter

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.