Skip to content

Tag: regex

Very Simple Regex Question

I have a very simple regex question. Suppose I have 2 conditions: url =http://www.abc.com/cde/def url =https://www.abc.com/sadfl/dsaf How can I extract the baseUrl using regex? Sample output: http://www.abc.com https://www.abc.com Answer Like this: However, you should use the URI class instead, like this:

Using Regular Expressions

I am having problems trying to use the regular expression that I used in JavaScript. On a web page, you may have: Renewal Date: 03 May 2010
I just want to be able to …

Regex for tree structures?

Are there regular expression equivalents for searching and modifying tree structures? Concise mini-languages (like perl regex) are what I am looking for. Here is an example that might clarify what I am looking for. An operation that would be possible on the above tree is “move subtree at node 2.1 into t…

Remove HTML tags from a String

Is there a good way to remove HTML from a Java string? A simple regex like will work, but some things like & won’t be converted correctly and non-HTML between the two angle brackets will be removed (i.e. the .*? in the regex will disappear). Answer Use a HTML parser instead of regex. This is dea…

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: Does anyone know w…