Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a truly universal wildcard in Grep? [duplicate]

Tags:

regex

bbedit

Really basic question here. So I'm told that a dot . matches any character EXCEPT a line break. I'm looking for something that matches any character, including line breaks.

All I want to do is to capture all the text in a website page between two specific strings, stripping the header and the footer. Something like HEADER TEXT(.+)FOOTER TEXT and then extract what's in the parentheses, but I can't find a way to include all text AND line breaks between header and footer, does this make sense? Thanks in advance!

like image 461
Tom B Avatar asked Dec 13 '09 19:12

Tom B


People also ask

Does grep support wildcard?

The wildcard * (asterisk) can be a substitute for any number of letters, numbers, or characters. Note that the asterisk (*) works differently in grep. In grep the asterisk only matches multiples of the preceding character. The wildcard * can be a substitute for any number of letters, numbers, or characters.

What is regex wildcard?

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.

What is star in grep?

"*" in the shell is <any string>. In egrep it's an operator that says "0 to many of the previous entity". In grep, it's just a regular character.

Which regex option matches any character including a new line?

Multiline option, it matches either the newline character ( \n ) or the end of the input string.


1 Answers

When I need to match several characters, including line breaks, I do:

[\s\S]*?

Note I'm using a non-greedy pattern

like image 128
Rubens Farias Avatar answered Nov 15 '22 06:11

Rubens Farias