Skip to content
Advertisement

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 …

What is the simplest way to convert a Java string from all caps (words separated by underscores) to CamelCase (no word separators)?

The title pretty much says it all. What’s the simplest/most elegant way that I can convert, in Java, a string from the format “THIS_IS_AN_EXAMPLE_STRING” to the format “ThisIsAnExampleString”? I figure there must be at least one way to do it using String.replaceAll() and a regex. My initial thoughts are: prepend the string with an underscore (_), convert the whole string

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 the subtree at node 1.” The result of the

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 dead simple with Jsoup. Jsoup

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 what I am doing wrong? Answer Try the following

Advertisement