Saturday, March 24, 2018

bash - sed substitution: for similar regex pattern match, the substitution result is very different

I am using sed to replace all HTML tags in a file



Text:





Hello World!







I have checked that basic regular expressions <.*\?> and <[^>]*> match only HTML tags in the text.



When I use sed 's/<.*\?>//g' [input-file], sed replaces everything and five blank lines are printed, whereas, sed 's/<[^>]*>//g [input-file] produces the correct output and first prints two blank line, then Hello World! with appropriate indentation on the next line and last two blank line.



Why does it behave differently for similar matches?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...