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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:00:17+00:00 2026-05-16T11:00:17+00:00

Trying to replace any non alpha-numeric characters with a hyphen. Can’t see why it

  • 0

Trying to replace any non alpha-numeric characters with a hyphen. Can’t see why it shouldn’t be working. It returns the original string unchanged.

item.mimetype = "image/png";

var mimetype = item.mimetype.toLowerCase().replace("/[^a-z0-9]/g",'-');
  • 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-16T11:00:18+00:00Added an answer on May 16, 2026 at 11:00 am

    Remove the quotes around the regex.

    As written, Javascript is looking for the string "/[^a-z0-9]/g"

    // This works
    "image/png".toLowerCase().replace(/[^a-z0-9]/g,'-'); 
    
    // And if writing unquoted regular expressions makes you feel icky:
    "image/png".toLowerCase().replace(new RegExp("[^a-z0-9]", "g"), '-');
    
    // And if I might do a full rewrite:
    "image/png".toLowerCase().replace(/\W/g, '-');
    

    More here

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

Sidebar

Related Questions

I'm trying to replace some non standard characters like ë,Ë,ç,Ç with numeric entities like
I'm trying build a regex that will replace any characters not of the format:
I am trying to build a regex function that will remove any non alpha
I am trying to replace a string that is surrounded by non word characters.
trying to use regex to replace any white space with  , inside of example
I am trying to replace a large string in groovy. But can't get it
I'm trying to replace the Orchard CMS NavigationManager in Orchard.UI.Navigation so I can filter
I'm trying to replace any <br /> tags that appear AFTER a </h2> tag.
I'm trying to replace any group of two or more periods with just a
note: I'm -not- trying to parse HTML with regex I'm trying to replace any

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.