tags:

views:

102

answers:

6

Hi

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"
+6  A: 

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

dejavu
+1  A: 

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
+1  A: 

On Movable Type try this:

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

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

Leniel Macaferi
Thanks for the quick one!
Maca
+1  A: 
s/ alt="[^"]*"//
M42
+1  A: 

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.

fabstab
A: 

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