Example: "This is just\na simple sentence".
I want to match every character between "This is" and "sentence". Line breaks should be ignored. I can't figure out, what the correct syntax is.
|
Example: "This is just\na simple sentence". I want to match every character between "This is" and "sentence". Line breaks should be ignored. I can't figure out, what the correct syntax is. |
|||||
|
|
For example
I used lookbehind The important thing here is that you activate the "dotall" mode of your regex engine, so that the The next thing is if you use Update
Where the (?s) turns on the dotall modifier, making the Update 2:
is matching your example "This is (a simple) sentence". See here on Regexr |
|||||||||||||||||||||
|
Lazy Quantifier NeededResurrecting this question because the regex in the accepted answer doesn't seem quite correct to me. Why? Because
will match You need a lazy quantifier between the two lookarounds. Adding a This matches what you want:
See demo. I removed the capture group, which was not needed. DOTALL Mode to Match Across Line Breaks Note that in the demo the "dot matches line breaks mode" (a.k.a.) dot-all is set (see how to turn on DOTALL in various languages). In many regex flavors, you can set it with the online modifier
Reference |
|||||||||||||
|
|
Try |
|||||||||
|
|
use this: |
|||||
|
|
This:
works in javascript. |
|||
|
|