1

In my HTML I have below tags:

<img src="../images/img.jpg" alt="sometext"/>

Using regex expression I want to remove alt=""

How would I write this?

Update

Its on movable type. I have to write it a like so:(textA is replaced by textB)

regex_replace="textA","textB"
Maca
  • 1,659
  • 3
  • 18
  • 42
  • [You can't parse XHTML with regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) ;-) – Andreas Dolk Jul 20 '10 at 08:27

6 Answers6

5

Why don't you just find 'alt=""' and replace it with ' ' ?

Ahmed Aman
  • 2,373
  • 1
  • 19
  • 33
1

What regex you are asking for ? Straight away remove ..

 $ sed 's/alt=""//'
    <img src="../images/img.jpg" alt=""/>
    <img src="../images/img.jpg" />

This does not requires a regex.

thegeek
  • 2,388
  • 2
  • 13
  • 10
1

On Movable Type try this:

regex_replace="/alt=""/",""

http://www.movabletype.org/documentation/developer/passing-multiple-parameters-into-a-tag-modifier.html

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
1

The following expression matches alt="sometext"

alt=".*?"

Note that if you used alt=".*" instead, and you had <img alt="sometext src="../images/img.jpg"> then you would match the whole string alt="sometext src="../images/img.jpg" (from alt=" to the last ").

The .* means: Match as much as you can.

The .*? means: Match as little as you can.

fstab
  • 992
  • 1
  • 11
  • 19
0
s/ alt="[^"]*"//
Toto
  • 89,455
  • 62
  • 89
  • 125
0

This regex_replace modifier should match any IMG tag with an alt attribute and capture everything preceding the alt attribute in group #1. The matched text is then replaced with the contents of group #1, effectively stripping off the alt attribute.

regex_replace='/(<img(?:\s+(?!alt\b)\w+="[^"]*")*)\s+alt="[^"]*"/g','$1'

Is that what you're looking for?

Alan Moore
  • 73,866
  • 12
  • 100
  • 156