| Author |
Regular expression
|
Duran Harris
Ranch Hand
Joined: Nov 09, 2008
Posts: 571
|
|
Hi exam-takers,
Was wondering if you guys would mind providing me with the regular expression to find :
Either '*','-','+','/'
I tried this:
Pattern p=Pattern.compile("[\\+\\*/-]");
But I dont get any matches...any tips??
|
===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
|
 |
Duran Harris
Ranch Hand
Joined: Nov 09, 2008
Posts: 571
|
|
|
Don't worry its working..
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
This would work too
The code does not necessarily need the \\ escape. Use \\ only to escape \ to represent other wildcards like \d
|
SCJP 6 articles - SCJP 5/6 mock exams - SCJP Mocks - SCJP 5 Mock exam (Word document ) - SCJP 5 Mock exam in Java.Inquisition format
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16687
|
|
Be careful here. The "-" sign has special meaning inside a character class. It should be the last character, if you want to disable the special meaning.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Deepak Bala
Bartender
Joined: Feb 24, 2006
Posts: 6588
|
|
Henry Wong wrote:
Be careful here. The "-" sign has special meaning inside a character class. It should be the last character, if you want to disable the special meaning.
Henry
Ah ! Thanks for pointing out. As an exercise you could try "[*-+/]+" and "[*+/-]+" to see what that means
|
 |
 |
|
|
subject: Regular expression
|
|
|