0

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!

3
  • If you are parsing HTML you should use an HTML parser. Commented Dec 10, 2010 at 23:58
  • stackoverflow.com/questions/701166/… Commented Dec 11, 2010 at 1:33
  • "split" takes a regex as the first argument Commented Dec 11, 2010 at 10:41

2 Answers 2

3

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])
Sign up to request clarification or add additional context in comments.

2 Comments

THanks for the response but I need to use Regex expressions
if you check the API for String.split, technically it is a regex :)
0
"Hello World!<TAG> &nsbp;".split("<")[0]

should return Hello World!.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.