Comparing a string with a pattern of type string

I am trying to write a program where I need to perform a comparison between a list of strings with a pattern (which is essentially a string). I'm not sure which term is being used, but this would be more of a log cleanup program if it helps.

Examples of input strings:

  • Hello World it's me
  • Hello, strange world, this is someone.
  • This is a test file
  • Hello World is a bot

For comparison with

and. Is it a file ?

b. Hello World is it ?

The idea is to match the introductory instructions (1-4) against the pattern strings (ab), and if they match, I need to act on them. Like sentence 1 and 4 b , but 2 .

Thanks in advance for your help / guidance.

+3


source to share


1 answer


Change ?

to .*

and you have a regex:

String input = "Hello World this is me";

if (input.matches("Hello World this is .*"))
    // true

      



etc.

+1


source







All Articles