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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:06:06+00:00 2026-05-29T04:06:06+00:00

Can anyone advise? And how does the replace all method works? message = message.replaceAll((?:https?|http?)://[\\w/%.\\-?&=!#]+,

  • 0

Can anyone advise? And how does the replace all method works?

message = message.replaceAll("(?:https?|http?)://[\\w/%.\\-?&=!#]+",
"<a href='$0' target='_blank'>$0</a>");
  • 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-29T04:06:06+00:00Added an answer on May 29, 2026 at 4:06 am

    You should be taken this each step at a time to understand:

    (?:https?|http?)
    

    | -> means OR so it means matches either https or http

    ? -> (only here) means optional elements, “s” from https is optional or “p” from http is optional too. What you probably meant is to do : “(https)?|(http)?“, make each optional. But this is still wrong, because you then could match a String like this one: “://someLink” – which does not make sense.

    I suppose you want to match https OR http, thus your regex here needs to changed to :

     https? (to make only the s optinal)
    

    ?: -> it defines a non-capturing group (it means it will be matched but not present in the output – not captured in the result), this is something related to regex groups.

    () -> mean that this is a group
    and as matter of fact this is the second group (the first is the whole match itself)

    This regex “://[\\w/%.\\-?&=!#]+” has been explained above pretty good I think.

    Here is the “magic” that happens here: “$0“, this is called a backreference to a matching group. So inside your message String, the result that you have matched with the regex:

    (?:https?|http?)://[\\w/%.\\-?&=!#]+
    

    will be replaced with this:

    "<a href='$0' target='_blank'>$0</a>"
    

    where $0 is actually the thing that was found with the first regex.

    Here is an example actually:

    // I've simplified: \\w+ any number of characters
    String regex = "https?://\\w+";
    String input = "http://value1 ; https://value2";
    input = input.replaceAll(regex, "<a href='$0' target='_blank'>$0</a> ");
    
    // this will output : 
    // <a href='http://value1' target='_blank'>http://value1</a>  ; <a href='https://value2' target='_blank'>https://value2</a>
    System.out.println(input);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have advise or can recommend a tool or CMS system with a
Can anyone advise on the appropriate SAS informat to read in a datetime (dd/mm/yyyy
Can anyone tell me how I can display a status message like 12 seconds
Does anyone know what the best method would be to work out how many
Can anyone tell me why my redirect helper does not work the way I'd
The code below does not adding rectangle. Can anyone advice What i missed ?
I'm trying something rather simple for the first time, can anyone advise. I'm just
can anyone give me any advice on what to do about this error ?!
i was wondering if any one can advise me on how i can go
Can anyone (maybe an XSL-fan?) help me find any advantages with handling presentation of

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.