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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:44:14+00:00 2026-06-14T09:44:14+00:00

I have searched SO (and Google) but not found any fully matching answer to

  • 0

I have searched SO (and Google) but not found any fully matching answer to my question:

I want to replace all swedish characters and whitespace in a String with another character. I would like it to work as follows:

  • “å” and “ä” should be replaced with “a”
  • “ö” should be replaced with “o”
  • “Å” and “Ä” should be replace with “A”
  • “Ö” should be replaced with “O”
  • ” ” should be replaced with “-“

Can this be achieved with regex (or any other way), and if so, how?

Of course, the below method does the job (and can be improved, I know, by replacing for example “å” and “ä” on the same line):

private String changeSwedishCharactersAndWhitespace(String string) {
    String newString = string.replaceAll("å", "a");
    newString = string.replaceAll("ä", "a");
    newString = string.replaceAll("ö", "o");
    newString = string.replaceAll("Å", "A");
    newString = string.replaceAll("Ä", "A");
    newString = string.replaceAll("Ö", "O");
    newString = string.replaceAll(" ", "-");
    return newString;
}

I know how to use regex to replace, for example, all “å”, “ä”, or “ö” with “”. The question is how do I replace a character using regex with another depending on which character it is? There must surely be a better way using regex than the above aproach?

  • 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-14T09:44:16+00:00Added an answer on June 14, 2026 at 9:44 am

    For latin characters with diacritics, a unicode normalization (java text) to retrieve basic letter code + diacritic combining code might help. Something like:

    import java.text.Normalizer;
    newString = Normalizer.normalize(string,
            Normalizer.Form.NFKD).replaceAll("\\p{M}", "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've searched the iPhone documentation and on google but have not found any information
I've searched in Google but have not found the answer? Can I execute phone
I have searched a bit on google, but didn't really found an answer to
I've searched Google for this, but have only found similar examples--not exactly what I
I've searched SO and Google but not found any answers on this. I am
I've searched google and SO for a solution to this problem but have not
this question may have been asked many times, but could not find any suitable
I've searched around for answers to this question, but not found anything quite on
I have searched through all the similar posts and google and have not quite
I want to Extract a zip file programatically. I have searched google but i

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.