2016-03-30 41 views
-4

更換多個字狀 -Java的正則表達式:在我有JSP代碼的JSP

<input type = "something" name = "something" value = "dto.value" /> 

現在我要替換「輸入」與「形式:輸入」刪除name屬性,添加新屬性「路徑」並設置「名稱」屬性值到路徑,如我的最終輸出將是 -

<form:input type = "something" path = "dto.value" /> 

如何實現它,因爲我需要做到這一點超過250層的JSP。

+1

你的問題不會好,如果你不公開具體的地步,你就完蛋了好評。你應該選擇一個正則表達式教程,並嘗試自己做,你可能會獲得寶貴的經驗,你將來可以應用。 – Aaron

+0

當然,在每一個jsp中手動執行它都太忙碌了。 – G555

+0

您是否在使用Eclipse @GauravKamble等IDE? – andrewdleach

回答

0

這是我做這做我的工作。

查找:

<input([^>]*value=")(\$\{([^"]*)\})"([^>]*) 

替換:

<form:input$1$2 path="$3" $4/ 
0

如果您使用的是Eclipse IDE,使用按Ctrl +˚F得到Find\Replace彈出窗口。然後檢查Regular expressions複選框。 分別在FindReplace with文本框中使用這些正則表達式。

查找:<(.*?)name\s*=\s*\"([^"]*)\"(.*)/>

替換爲:<form:\1 \3 path="\2" />

正則表達式說明:

<    # starting of the tag 
(.*?)   # group 1 - all the characters till the word 'name' 
name\s*=\s*  # the word 'name' and '=' with spaces in between 
\"    # starting of the name attribute value 
([^"]*)   # group 2 - the value of name attribute 
\"    # end of the name attribute value 
(.*)   # group 3 - all the other attributes and values 
/>    # end of the tag