File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex

 
sahid ul karim
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string like :- String str="This 'is' really good work";
i want to find 'is' . What should be the regex for this ?
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have to use regex ? str.indexOf("'is'") will do what you want.
 
Bill Cruise
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The regex for 'is' is "'is'".
 
Piet Verdriet
Ranch Hand
Posts: 266
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's the actual String "is" you're looking for, a simple indexOf(...) will do just fine, as already suggested.
If you want to capture text between ' (single quote), here's a way to do that:
 
Alan Moore
Ranch Hand
Posts: 262
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That regex is more complicated than it needs to be, Piet--or at least, more advanced. The OP didn't even mention needing to extract the word from within the apostrophes, but if you really need to, using capturing groups is simpler:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic