HOW TO MATCH TEXT BETWEEN DOUBLE SLASHES BUT NOT URL?

Ida B Wells

Total Post:30

Points:210
Posted by  Ida B Wells
Java 
 1151  View(s)
Ratings:
Rate this:

I need to replace double slashes in a wiki markup with something else (double slashes stands for italic text).

How can I match italic text, without URLs?

This regexp is for a text where are no URLs: //(.*?)//

Problem appears when there is a text like:

//italic text// and this is only http://some.url/somewhere and this is //another italic text// yeah

I'm using Java.

  1. Garry Winogrand

    Post:24

    Points:168
    Re: How to match text between double slashes but not url?

    Hey Ida

    Use this Code:

    (?<!:)//(.+?)//

    It requires that // does not have : in front of it. This would catch most URL forms.

    Also, I changed your (.*?) to (.+?) - it requires at least 1 character between // to be valid - your code would allow ////.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!