• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regular expression

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't worry its working..
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would work too



The code does not necessarily need the \\ escape. Use \\ only to escape \ to represent other wildcards like \d
 
Henry Wong
author
Marshal
Pie
Posts: 21432
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic