Free Lancer
Free Lancer

Reputation: 1000

Regex Patterns in Java

I am using Regex Patterns and I need to check that the beginning of the String is an HTML Simple Text and return that String. So for example:

Hello World!<TAG> &nsbp;

Should return:

Hello World!

Upvotes: 0

Views: 187

Answers (2)

David O&#39;Meara
David O&#39;Meara

Reputation: 3033

Remember that if you're parsing large sections of text or entire files, you should force the String into a new reference otherwise you may get a memory leak due to substrings.

new String("Hello World!<TAG> &nsbp;".split("<")[0])

Upvotes: 3

thejh
thejh

Reputation: 45568

"Hello World!<TAG> &nsbp;".split("<")[0]

should return Hello World!.

Upvotes: 0

Related Questions