Saturday, April 24, 2010

Partial HTML parser

This is a partial HTML parser. This will parse and . But it will not parse and value inside parent tag (eg:
. Will only parse
not the
inside). This is for learning purpose.

Expression : "\\<(\\S*).*?>.*?"

To make this work in java you have to set the dotall mode in pattern.

Pattern pattern =
Pattern.compile("\\<(\\S*).*?>.*?",Pattern.DOTALL);

*dotall mode means . also represents line terminator

Here \\< for < character, (\\S*) for any character which is not whitespace, .* for any character including whitespace (? for parsing Reluctant parsing. Please refer the Reluctant parsing in ) , > for that character, .* for any character including whitespace (? for parsing Reluctant parsing), for that character.

Simple Float / Double validation using regex

This is a simple regex expression to validate a float/double value.

" on the start and end of the below regex is not part of the expression.

Expression : "\\d*\\.\\d+"

pass - 23.45 , .3
fail - 23. , .


In the above expression the part \\d* denotes zero or more digits.\\d is to represent digit and * for zero or more. The next one \\. is for the dot character. And finally \\d+ for at least one or more digits. Here + is for one or more.

Thursday, April 15, 2010

First post

This is my first post. I am planning to write my findings on regular expressions in java / regex in java. Hope it will help you a lot.