2012-07-19 64 views
0

我有一個JSF標籤:想用正則表達式替換標籤中的值屬性?

<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> 

我想替換屬性value的價值,改變屬性名稱styleClass到「類」?是否可以通過regex

任何幫助,將不勝感激。

P.S.我是正則表達式的noob,所以無法自己弄清楚。

編輯:

我做它在Eclipse中。

+0

你爲什麼要使用正則表達式,而不是DOM?你是否試圖在你的IDE中使用find-and-replace來做到這一點? – 2012-07-19 12:45:31

+0

是的,這是可能的,但你爲什麼要?什麼語言?什麼環境?目的是什麼? – 2012-07-19 12:45:51

+0

@MattBall:是的,我在Eclipse中做。 – HashimR 2012-07-19 12:46:37

回答

1

只要你從來沒有在你的價值報價,你可以這樣做:

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

,爲的styleClass

Find  : <h:graphicImage ([^>]*)styleClass=([^>]*)> 
Replace with: <h:graphicImage \1class=\2> 
0

這是JSF標籤,其中JSF庫將轉換,從styleClass在頁面發送作爲響應時轉換爲類。

,並且可以使用在JavaScript中改變它的值:

document.getElementById("expandImage").value="some value";