Saturday 24 March 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

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...