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 How to use import java.util.regex.Pattern ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to use import java.util.regex.Pattern ?" Watch "How to use import java.util.regex.Pattern ?" New topic

How to use import java.util.regex.Pattern ?

somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312

Result for complied above code

java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
at java.util.regex.Pattern.error(
at java.util.regex.Pattern.sequence(
at java.util.regex.Pattern.expr(
at java.util.regex.Pattern.compile(
at java.util.regex.Pattern.<init>(
at java.util.regex.Pattern.compile(
at com.spns.history.TestPattern.main(
Exception in thread "main"

Why i don't use "*" in pattern?

p.s. When i remove "*" is work fine.

Java Developer, Thailand
Amit Ghai
Ranch Hand

Joined: Mar 24, 2004
Posts: 35
The '*' character by itself does not mean anything in regular expressions. If it follows a character, character class, or group, then it means 'zero or more' of the thing it follows.

If your intention with "*welcome" is "zero or more of any character, welcome" then the expression you want is: ".*welcome";
The '.' character will match any character, and the '*' works as stated above.

Reasonable people adapt themselves to the world. Unreasonable people attempt to adapt the world to themselves. All progress, therefore, depends on unreasonable people.
I agree. Here's the link:
subject: How to use import java.util.regex.Pattern ?
It's not a secret anymore!