-4

I have a string here

Some text here

Maybe something here too

Work hard in silence

let your success


make noise

rest of the paragraph here with some

new lines too

My goal is to find and remove Work hard in silence let your success and also the text before it.

How do I tell regex to find in target string without taking new lines into account?

Final result should be the remaining string keeping the new lines in it.

make noise

rest of the paragraph here with some

new lines too
khelwood
  • 46,621
  • 12
  • 59
  • 83
Umair Ayub
  • 13,220
  • 12
  • 53
  • 124

1 Answers1

0

This is very basic RegExp, you need Work\s+hard\s+in\s+silence\s+let\s+your\s+success\s+make\s+noise

Your current RegExp is searching for a literal match, that means each space character must be a space character - it is not implicitly any kind of whitespace character. You need to use \s, which matches any whitespace character (equal to [\r\n\t\f\v ]). The quantifier + expects at least one whitespace.

EDIT

I am not sure if it was not in the initial requirements - but if you want to keep multiline mode active and match everything until the end of your searched sentence:

[\S\s]*Work\s+hard\s+in\s+silence\s+let\s+your\s+success\s*
wiesion
  • 2,118
  • 8
  • 19