I'm trying to create a regex that will select an entire line where it contains a matching string.
I can't seem to get it to work. Here is the expression:
^.*?(\bEventname 2\b).*$
You can see the test case and what I've tried here:
I'm trying to create a regex that will select an entire line where it contains a matching string.
I can't seem to get it to work. Here is the expression:
^.*?(\bEventname 2\b).*$
You can see the test case and what I've tried here:
This answer solves the question with 463 steps instead of 952 steps. Just ensure a new line at the end of the file.
.*Eventname 2.*\n
https://www.regex101.com/r/mT5rZ3/5
With .*Eventname 2.*\n?
it also solves with 463 steps, but there is no need to ensure a new line at the end of the file.
Try this:
(.*(?:Eventname 2).*)
explaination:
(
... )
: groups and captures the line
(?:
...)
: groups without capturing the string that the line needs to contain
.*
: any characters
If you are using the PHP regex . don't match newlines. So
.*(\bEventname 2\b).*
would be enough. If . matches newline you would need *? to make the dots non-greedy (so it just matches one line, instead of everything). You also need to be in multi-line mode to use ^ and $, but that shouldn't be necessary (since you only want to match one line anyway).
You are using a string containing several lines. By default, the ^
and $
operators will match the beginning and end of the whole string. The m
modifier will cause them to match the beginning and end of a line.
.*Eventname 2.*
.