Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex match line containing string

Tags:

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.

Any help is greatly appreciated. You can see the test case and what I've tried here:

https://www.regex101.com/r/mT5rZ3/1

Many thanks in advance! :-)

like image 686
Dyvel Avatar asked Jul 31 '15 11:07

Dyvel


People also ask

How do I match an entire line in regex?

To expand the regex to match a complete line, add ‹ . * › at both ends. The dot-asterisk sequences match zero or more characters within the current line. The asterisk quantifiers are greedy, so they will match as much text as possible.

What is ?! In regex?

The ?! n quantifier matches any string that is not followed by a specific string n.

How do you use wildcards in regex?

In regular expressions, the period ( . , also called "dot") is the wildcard pattern which matches any single character. Combined with the asterisk operator . * it will match any number of any characters.


1 Answers

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

like image 117
user Avatar answered Sep 18 '22 14:09

user