I have this example:
This is a simple test text.
Yet another line.
START: This is the part that
needs match.
This part does not need
capture.
Wherever else text.
I want to match this part:
START: This is the part that
needs capture.
The point is I know the START:
is there and it ends with a new line that has anything but a space after it.
I have tried a lot of combinations starting from: START: (.*?)
I have plaid around with \r and anything I could think of to match only if it has no white-space.
I am not a noob asking because I am lazy. I spent a few hours before asking.
How about this:
preg_match(
'/^ # Start of line
START:\ # Match "START: "
.* # Match any characters except newline
\r?\n # Match newline
(?: # Try to match...
^ # from the start of the line:
\ + # - one or more spaces
.* # - any characters except newline
\r?\n # - newline
)* # Repeat as needed/mx',
$subject)
This assumes that all lines are newline-terminated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With