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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:10:01+00:00 2026-06-03T07:10:01+00:00

I have a string like: This is my abc.def ght.123 example 12.34 test I’d

  • 0

I have a string like:

"This is my abc.def ght.123 example 12.34 test"

I’d like to change to:

"This is my \"abc def\" \"ght 123\" example 12.34 test"

How to do using regular expression in java?
Thanks
Isa

  • 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-03T07:10:02+00:00Added an answer on June 3, 2026 at 7:10 am

    If there are only one-dot sequences like abc.def or ght.123 try the following:

    String input = "This is my abc.def ght.123 example 12.34 test";
    
    input = input.replaceAll("\\b([a-zA-Z]+)\\.([a-zA-Z0-9]+)\\b", "\\\"$1 $2\\\"");
    
    System.out.println( input );
    //output: This is my "abc def" "ght 123" example 12.34 test
    

    The expression used is means: any sequence of characters followed by a dot and a sequence of characters or digits (the \b is a word boundary to prevent matches of (_abc.def, if you want them as well you could add the underscore to the character class or remove the \b).

    The replacement would then replace the match with \"$1 $2\" where $1 is the content of the first group ([a-zA-Z]+) and $2 is the content of the second group ([a-zA-Z0-9]+).

    Update:

    For the required input "This is my complexe string 12.34 ab.cd a+-.12 34.0+b zer.123.456 or 12.34.56 etc" (see the comment), the following expression might be used:

    (?i)(?<=^|\s)([a-z\+\-]+)\.([a-z0-9\+\-]+)(?=\s|$)
    

    Here (?i) means the expression should be case insensitive, (?<=^|\s) means match either if we’re at the start of the string or after a whitespace, (?=\s|$) means match if a whitespace or the end of the string follows.

    The core expression is still ([a-z\+\-]+)\.([a-z0-9\+\-]+). As you can see, I only added + and - to the character classes (note that it would be possible to write - instead of \- but then the meaning of the minus character would depend on its position in the character class). If you want to support more characters, add them to the character classes as needed. For more information on predefined character classes like \d or p{L} see here and here.

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

Sidebar

Related Questions

Say, I have an XML String like this, <METHOD>foo</METHOD> <PARAM1>abc</PARAM1> <PARAM2>def</PARAM2> ... <PARAM99>ghi</PARAM99> <PARAM100>jkl</PARAM100>
i have one dictionary that has entries that looks like this: dictionary[ABC.123] = Test
I have a string that looks like this: abc[1,2,3].something.here,foo[10,6,34].somethingelse.here,def[1,2].another I want to split this
I have a string like this: String a = 'ABC(rfg) OR DEF(3dsgf56737(fg)sdg) OR KLM(dfgrg)
I have a string like this: abc=foo&def=%5Basf%5D&xyz=5 How can I convert it into a
I have a string like this \u041a\u043b\u0443\u0431 Test; It was decoded by json_encode(), the
I have a string/pattern like this: [xy][abc] I try to get the values contained
I have strings that look like this: 1. abc 2. def 88. ghi I'd
I have strings like this: var abc = 002; var def = 023; How
Assuming I have this string: abc{def{ghi{jkl}mno{pqr}st}uvw}xyz and I want to match this: {def{ghi{jkl}mno{pqr}st}uvw} what

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.