Replacing html content using sed and regex

Viewed 59

I am trying to replace the content of some HTML content using sed in a bash script. For some reason I'm not getting the proper result as it's not replacing anything mainly the regex part

HTML i want to replace

<h3 class="indicate-hover css-5fzt5q">For the Most Complex Heroines Animation
<h3 class="indicate-hover css-1pvrrwb">The Psychology Behind Sibling

to

 head For the Most Complex Heroines Animation
 head The Psychology Behind Sibling

i used

  sed -e 's/<h3 class="indicate-hover css-([a-b0-9]+)">/head/g'

mainly ([a-b0-9]) this part is getting failed in execution , i must be missing something out,i want to get it more specific , i have "<p class="summary-class css-1azn4ub">How many words can" i want to substitute it to 'tail ' and have many more other tags . The regex part is giving me the pain

2 Answers

Using sed

$ sed 's/.*-[[:alnum:]]\+">/head /' input_file

Output

head For the Most Complex Heroines Animation
head The Psychology Behind Sibling

You need to use \+, unless you use sed -E

  • \+ is a valid quantifier in the (default) Basic regular expressions
  • + is a valid quantifier in Extended regular expressions
Related