Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Search text  RSS feed

 
Mayank Jaswal
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to search some string in a text and find its position using

Pattern p_Pattern = Pattern.compile(searchtext);
Matcher m_Matcher = p_Pattern.matcher(Text In which string is to be searched );
m_Matcher.start();

I am able to search normal string but if the string contains some special character then i am not able to search the same

example

If text is " aaa dsjkjjd kkiuyydd lklloi hhh$hhhh llinn "

now if i search for "dsjkjjd" it is being searched and its position is being displayed but
for "hhh$hhhh" i am not able to search .
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/EaseUp

Also, start() doesn't do any searching. That's what find() does. After find() returns true, start() returns the start position of the match.

And you should check the API of Pattern. $ has a special meaning.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless there are requirements you didn't mention, it sounds as if String.indexOf would be sufficient for this kind of search. No need to get into regexps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!