In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, I would like to share with you the relevant knowledge points of Linux's regular expression example analysis, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Regular expression (regular expression) describes a string matching pattern (pattern), which can be used to check whether a string contains a certain substring, replace a matching substring, or extract a substring from a string that meets a certain condition.
Metacharacters are usually divided into two categories in Linux: Shell metacharacters, which are parsed by Linux Shell; regular expression metacharacters, which are parsed by text processing tools such as vi/grep/sed/awk; and regular expressions are generally processed as text lines. Set the-color parameter for the grep command before performing the following example:
Class= "" > $alias grep='grep-- color=auto'
In this way, the string filtered out each time will be colored.
One more thing to do before you begin is to create a re-file file for testing, as follows:
Class= "" > $cat re-fileI had a lovely time on our little picnic.Lovers were all around us. It is springtime. Ohlove, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.is forever. I live for you. It's hard to get back in thegroove.class= "> $cat linux.txtLinux is a goodgod assdxw bcvnbvbjkgreatttttt wexcvxcoperaaaating dhfghfvxgooodfs awrerdxxhklgdsystem awxxxxgladgood regular expression metacharacter special metacharacter extension regular expression
Teach you 3 minutes to finish Linux regular expression teach you 3 minutes to finish Linux regular expression practice
Match all lines that start with love
Class= "> $grep'^ love' re-filelove, how much I adore you. Do you know
Match all lines at the end of love
Class= "> $grep 'love$' re-fileclover. Did you see them? I can only hope love.
Matches all lines that start with l, contain two characters in the middle, and end with e
Class= "" > $grep'l... e' re-fileI had a lovely time on our little picnic.love, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.is forever. I live for you. It's hard to get back in the
Matches 0 or more blank lines, followed by love characters
Class= "" > $grep'* love' re-fileI had a lovely time on our little picnic.love, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.
Match love or Love
Class= "> $grep'[Ll] ove' re-file # is case-insensitive to l. It is springtime. Ohlove, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.
Matches the letter Amurz, followed by ove
Class= "" > $grep'[Amurz] ove' re-fileLovers were all around us. It is springtime. Oh
Match any character lines that are not in the Amurz range, all lowercase characters
Class= "" > $grep'[^ Amurz] 're-fileI had a lovely time on our little picnic.Lovers were all around us. It is springtime. Ohlove, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.is forever. I live for you. It's hard to get back in thegroove.
Match love
Class= "" > $grep 'love\. " Re-fileclover. Did you see them? I can only hope love.
Match Spac
Class= "> $grep'^ $'re-file
Match any character
Class= "> $grep'. * 're-fileI had a lovely time on our little picnic.Lovers were all around us. It is springtime. Ohlove, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.is forever. I live for you. It's hard to get back in thegroove.
The preceding o character is repeated 2 to 4 times
Class= "> $grep'o\ {2pm 4\} 're-filegroove.
Repeat the o character at least 2 times
Class= "> $grep'o\ {2,\} 're-filegroove.
Repeat 0 character up to 2 times
Class= "> $grep'o\ {, 2\} 're-fileI had a lovely time on our little picnic.Lovers were all around us. It is springtime. Ohlove, how much I adore you. Do you knowthe extent of my love? Oh, by the way, I thinkI lost my gloves somewhere out in that field ofclover. Did you see them? I can only hope love.is forever. I live for you. It's hard to get back in thegroove.
Repeat one or more of the previous character
Class= "> $egrep" go+d "linux.txtLinux is a goodgod assdxw bcvnbvbjkgooodfs awrerdxxhklgood#0 or one character ansheng@Ubuntu:/tmp$ egrep" go?d "linux.txtgod assdxw bcvnbvbjkgdsystem awxxxx
Or, find multiple strings
Class= "" > $egrep "gd | good" linux.txtLinux is a goodgdsystem awxxxxgood
Packet filter matching
Class= "> $egrep" g (la | oo) d "linux.txtLinux is a goodgladgood is all the content of the article" regular expression example Analysis of Linux ". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.