-2

This is what I am trying to do...

Enter Pattern
//*//_//*
Enter Text
hello *_* how are you?
No match found

I know to avoid treating above characters as Metacharacters I need to use these escape sequences. I don't know how to do with _ (underscore sigh)

I even tried

//* _ //*

Still it didn't work.

code

Scanner sc = new Scanner(System.in);
System.out.println("Enter pattern");
Pattern pattern = Pattern.compile(sc.nextLine());
System.out.println("Enter Text");
Matcher matcher = pattern.matcher(sc.nextLine());
boolean found = false;

while(matcher.find())
{
    System.out.println("I found the text" + matcher.group() + "Starting index" + matcher.start() + "Ending at index" + matcher.end());
    found = true;
}
if(!found)
{
    System.out.println("No match found");
}
khelwood
  • 55,782
  • 14
  • 81
  • 108
dexter
  • 1
  • 1

1 Answers1

-1

If you are trying to match the *_* part of the input, try the following pattern:

\*\_\*
Matt Clegg
  • 359
  • 1
  • 4
  • 17