File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Regular expression" Watch "Regular expression" New topic
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
    
    1

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
    
  19



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
    
    1

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regular expression
 
Similar Threads
Please share any Java code to do email validation
Regular expression to find whether line DOES NOT end with a specific pattern
Validating The Date String
Anything wrong this regular expression
regular expression which doesnt alllow *