0

I have a jsf tag:

<h:graphicImage styleClass="iconButton" id="expandImage" onclick="toggleFilter();" onmouseout="onMouseOutExpandButton();" onmouseover="onHoverExpandButton();" value = "./resources/images/allFilter_idle.gif" style="cursor:pointer; margin-top : 6px; margin-bottom: 6px; margin-right: 3px;"> </h:graphicImage>

I want to replace the value of attribute value and also change attribute name styleClass to 'class' ? Is it possible through regex.

Any help would be appreciated.

P.S. I'm a noob in regex, so wasn't able to figure it out myself.

EDIT:

I'm doing it in Eclipse.

HashimR
  • 3,803
  • 8
  • 32
  • 49
  • Why are you using regex and not the DOM? Are you trying to do this in your IDE with find-and-replace? – Matt Ball Jul 19 '12 at 12:45
  • Yes, it's possible, but why would you want to? What language? What environment? What purpose? – J. Steen Jul 19 '12 at 12:45
  • @MattBall: Yes, i'm doing it in Eclipse. – HashimR Jul 19 '12 at 12:46
  • 3
    Please refrain from parsing HTML with RegEx as it will [drive you į̷̷͚̤̤̖̱̦͍͗̒̈̅̄̎n̨͖͓̹͍͎͔͈̝̲͐ͪ͛̃̄͛ṣ̷̵̞̦ͤ̅̉̋ͪ͑͛ͥ͜a̷̘͖̮͔͎͛̇̏̒͆̆͘n͇͔̤̼͙̩͖̭ͤ͋̉͌͟eͥ͒͆ͧͨ̽͞҉̹͍̳̻͢](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). Use an [HTML parser](http://stackoverflow.com/questions/292926/robust-mature-html-parser-for-php) instead. – Madara's Ghost Jul 19 '12 at 12:47
  • @Truth How did you do that: http://i.stack.imgur.com/UNrP4.png – hjpotter92 Jul 19 '12 at 12:55
  • @Truth he just wants to replace values in an editor, its for sure the fastest and easiest way to do this with regex and its makes perfect sense. – morja Jul 19 '12 at 13:02

2 Answers2

1

As long as you never have a quote in your value, you could do:

Find        : <h:graphicImage ([^>]*)value=".*?"([^>]*)>
Replace with: <h:graphicImage \1value="new value"\2>

and for the styleClass

Find        : <h:graphicImage ([^>]*)styleClass=([^>]*)>
Replace with: <h:graphicImage \1class=\2>
morja
  • 8,297
  • 2
  • 39
  • 59
0

This is JSF Tag, where JSF library will convert that from styleClass to class when the page is sent in response.

And you can change the value of it in javascript using:

document.getElementById("expandImage").value="some value";
chiwangc
  • 3,566
  • 16
  • 26
  • 32
Rohan S Raju
  • 426
  • 3
  • 7
  • 20