Skip to content
Advertisement

Regular expression to match URLs in Java

I use RegexBuddy while working with regular expressions. From its library I copied the regular expression to match URLs. I tested successfully within RegexBuddy. However, when I copied it as Java String flavor and pasted it into Java code, it does not work. The following class prints false:

JavaScript

Does anyone know what I am doing wrong?

Advertisement

Answer

Try the following regex string instead. Your test was probably done in a case-sensitive manner. I have added the lowercase alphas as well as a proper string beginning placeholder.

JavaScript

This works too:

JavaScript

Note:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement