Blog Archives

8 Regular Expressions (aka Regex) by examples for Java developers

Q1 How will you go about implementing the following validation rules for a user name?

— user name must be between 2 and 17 characters long.
— valid characters are A to Z, a to z, 0 to 9, . (full-stop), _ (underscore) and – (hyphen)
— user name must begin with an alphabetic character.
— user name must not end with a . (full stop) or _ (underscore) or – (hyphen).

A1 The above rules can be implemented with a regular expression as shown below:

Not compiling the regular expression can be costly if Pattern.matches( ) is used over and over again with the same expression in a loop or frequent method calls because the matches( ) method will re-compile the expression every time it is used.… Read more ...

Regular Expressions interview Q&As for Java developers

Q1 What’s the difference between a wildcard and a regular expression? A1 A wildcard is a generic term referring to something that can be substituted for all possibilities. In computer terms, usually a simple “wildcard” is just a * that can match one or more characters, and possibly a ?…

Read more ...

500+ Enterprise & Core Java programmer & architect Q&As

Java & Big Data Tutorials