1

I've the below string, Now I want to match the string if it contains Continue? [Y/N]. I tried couple of ways but it didn't worked as expected. Any suggestions to match the complete string if contains Continue? [Y/N]

Input String:

Warning: do you want to proceed, some-more,text. Continue? [Y/N]
Prasad
  • 1,116
  • 10
  • 22

1 Answers1

2

Try the following regex:

(?=^.*Continue\? \[Y\/N]$)(^.*Continue\? \[Y\/N]$)

The first group is a positive look ahead checking whether Continue? [Y/N] exists at the end of the line or not, if it exists the second group matches the whole string , you can see test cases at link given below. Note: the special characters has to be escaped to match it literally, [ , ? and /. since you are using java you need also to escape, \ .

(?=^.*Continue\\? \\[Y\\/N]$)(^.*Continue\\? \\[Y\\/N]$)

See text at regex101

The Scientific Method
  • 2,266
  • 2
  • 11
  • 23