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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regular expression" Watch "Regular expression" New topic
Author

Regular expression

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

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: 598

Don't worry its working..
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

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 - More SCJP Mocks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18101
    
  39



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: 6657
    
    5

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
Anything wrong this regular expression
Please share any Java code to do email validation
Validating The Date String
regular expression which doesnt alllow *
Regular expression to find whether line DOES NOT end with a specific pattern