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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:20:43+00:00 2026-06-04T23:20:43+00:00

I am using the current expression to convert plain text hyperlink like with http

  • 0

I am using the current expression to convert plain text hyperlink like with http or https to html hyperlinks

String pattern = "(?:https|http)://([^\\s\\|]+)";

However in the message content that will go through this regular expression pattern i have content like http://www.yahoo.com.

For this kind of content in between the two video brackets. I do not want it to be converted to html hyperlink because it will be displayed on the page.

How to resolve this issue?

  • 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-04T23:20:45+00:00Added an answer on June 4, 2026 at 11:20 pm

    Use negative lookahead and lookbehind using (?<!...) and (?!...):

    String link = "(?:https|http)://([^\\s\\|]+)";
    String pattern = "(?<!\\)" + link + "(?!\\)";
    
    Pattern p = Pattern.compile(pattern);
    System.out.println(p.matcher("http://www.yahoo.com").matches());
    System.out.println(p.matcher("http://www.yahoo.com").matches());
    

    Outputs:

    false
    true
    

    Full example:

    public static void main(String... args) {
    
        Pattern pattern = Pattern.compile(
                "(?<!\\)(?:https|http)://([^\\s\\|]+)(?!\\)");
    
        String text = "This is some example text with a link" +
            "http://videolink that should not be replaced" + 
            "and another link that should be" +
            "replaced http://www.example.com";
    
        Matcher m = pattern.matcher(text);
    
        StringBuffer sb = new StringBuffer();
        while (m.find())
            m.appendReplacement(sb, "<a href=\""+m.group()+"\">"+m.group() +"</a>");
        m.appendTail(sb);
    
        System.out.println(sb);
    }
    

    Outputs:

    This is some example text with a link
    http://videolink that should not be replaced
    and another link that should be
    replaced http://www.example.com

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

Sidebar

Related Questions

Using the guide http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html i'm trying to customize error message, but i've a problem:
From http://metacpan.org/pod/XML::LibXML::Node : find evaluates the XPath 1.0 expression using the current node as
I find myself using the current pattern quite often in my code nowadays var
Using Php I would like to extract the current Url of a page including
I'm trying to extract/match data from a string using regular expression but I don't
I'm using lambda expression and trying convert into uint while adding into the Hashset.
The following is a sample string I'm using:  http://www.asfradio.com/device.asp?u=username&p=password&s=east Current checks I use in
I'm writing an SQL expression and I'd like to use the current month as
I would like to know how to write a Linq (using lambda Expression in
Is it possible to convert a lambda expression like x => x + 1.5

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.