-4

I want a regular expression that can match <FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT> or

<LI><FONT FACE=\"Verdana\" SIZE=\"12\"> My Name is xyz </FONT></LI> and it should not be greedy

6
  • Which part are you looking for and which parts can vary? Are you looking for exactly that string, or are you looking for "My Name is" whatever the font face is, or what? Commented Aug 16, 2010 at 17:56
  • possible duplicate of Java Regular expression Commented Aug 16, 2010 at 17:58
  • I am looking for a regex which will match either of the 2 strings completely above. Commented Aug 16, 2010 at 18:01
  • @java_geek: .* will match those 2 strings completely. And many other strings as well. If you don't want to match the other strings, then say what those strings are. It always helps to be specific in saying what you want to match and what you don't want to match in regex questions. Commented Aug 17, 2010 at 6:15
  • ok....assume that there is a huge file and u want to match either of the above lines using ur regular expression. Thats what i want exactly Commented Aug 17, 2010 at 7:20

4 Answers 4

6

Three questions in as many hours. Must be a record of some sorts.

For the sake of humanity, don't use regular expressions to parse XML!

Sign up to request clarification or add additional context in comments.

5 Comments

i am aware that u cannot parse HTML using regex.
Is there then any specific reason why you are using regular expression to parse the HTML snippet?
Yeah, i have a specific html file and i need to do some kind of manipulation on it. I am not looking for a generic html parser.
Is there something in the 'specific' HTML file that a 'generic' XML/HTML parser cannot handle?
all HTML parsers are specific to HTML. use an HTML parser, that is what they are for parsing all HTML.
2

You should not be using regular expressions for this

Comments

1

Why not use a Java XML parser?

3 Comments

What...Google is of no use? Perhaps the OP should've used Bing?
if you have a problem and solve it with a regular expression, now you have 2 problems. If you don't think HTML and XML parsers are of any use then you will never understand the reasons no body will answer your question with what you want ... because they can't.
@fuzzy Who are you talking to?
0

You can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool that is insufficiently sophisticated to understand the constructs employed by HTML. HTML is not a regular language and hence cannot be parsed by regular expressions. Regex queries are not equipped to break down HTML into its meaningful parts

the beginning of the answer to this exact question with over 4300 up votes. If you don't understand this and insist on ignoring this advice then you probably should not be programming.

What happens when FACE and SIZE are in opposite order?

4 Comments

This link is in a previous answer, you even commented on it. Aside from going on a meaningless rant and asking a question, what new information does this answer provide?
@Sam More than your comment on a 2 year old question/answer!
You updated this about an hour ago...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.