File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Regular Expression Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regular Expression Question" Watch "Regular Expression Question" New topic

Regular Expression Question

Ranch Hand

Joined: Dec 08, 2004
Posts: 111

Can any one give me some sample examples about these regular expressions.
sasi kala
Ranch Hand

Joined: Dec 17, 2004
Posts: 68
Hi sanat kumar,

As far as i know,

"^[a-zA-Z]*$" ---- means an expression starts with a,b,c...z or A,B,C..Z
example, a

"^[A-Z]\\d[A-Z]\\d[A-Z]\\d$" --- means [A-Z] single char between A,B..Z
\\d means 0,1,...9 any on char

like that "B3E3S1". Note that here not * is given it mean only on char.

to represent "SLFDJLK3alsdkjf" or "KHDJKFHJK3" in regular expression use

^[A-Z]*\\d[a-z]*$ --- starts with zore or more capitals, there should be one digits after that zero or more small alphabets.

Hope this helps you.

All The Best
Ranch Hand

Joined: Dec 08, 2004
Posts: 111

Thanks sasi kala for your quick reply.
Ranch Hand

Joined: Dec 08, 2004
Posts: 111

Hi all,

What are the characters ^ and $.

Can anyone give a validation rule for email ids.

Thanks in advance.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I downloaded a tool called RegEx Coach. It has a free trial period but you may find you want to pay for it. When you highlight part of an expression it gives a plain English description. It's neat to work interactively with a tool like that while learning regular expressions.

One note: That particular tool is not 100% compatible with Java's regex. Plus you have to add escape characters in Java. Google for regular expression tools in Java for more. There is one that works as an Eclipse plugin if that sounds useful.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
The Pattern class javadoc will help you with regex expressions.

^ means not
$ means end of line

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Robert Lofthouse

Joined: Dec 28, 2004
Posts: 2
Just to clear this up:

^ matches the beginning of the line, however, when its inside a character class (i.e. [^a-z]) it means 'not'.

Therefore: ^[a-zA-Z] would be mean 'match any uppercase or lowercase letter at the beginning of a line'.

$ matches the end of a line

* means 'match 0 or more occurances of the preceding character'.


^[a-zA-Z]*$ means: Match a string that starts with 0 or more characters that are either uppercase or lowercase. The string must consist fully of letters.

The following would match:


The following wouldn't match:

I agree. Here's the link:
subject: Regular Expression Question
It's not a secret anymore!