I have a problem to build good regular expressions to find and replace. I need to replace all urls in many .jsf files. I want replace ulrs staring by XXX with <c:url value="URL_WITHOUT_XXX"/>. Examples below.
I stuck with find regular expression "XXX(.*)" and replace expression "<c:url value="\1"/>", but my find expression match to long string , for example "XXX/a" style="", but need that match only to first " (href end). Anybody helps ?
I have:
<a href="XXX/a" style="">
<a href="XXX/b" >
<a href="XXX/c" ...>
I want:
<a href="<c:url value="/a"/>" style="">
<a href="<c:url value="/b"/>" >
<a href="<c:url value="/c"/>" ...>
PS: Sorry for my poor english 😉
Edit:
I use Find/Replace in Eclipse (regular expressions on)
You should specify the language you’re working with.
The following regex will match what you want:
If you want to have some particular value, you can group the regex according to your needs. For example:
will give you in the first group:
If you want to have only
/a,/b, and/c, you can group it like that:Edit:
I will explain what
<a href="XXX[^\"]*"does:<a href="XXX"zero or many times:[^\"]*", which is not really necessaryWhen you do:
[^abc]you’re telling it to match anything but nota, orb, orc.So
[^\"]is: Match anything except a".And the quantifier
*means zero or more times, soa*will match either an empty string, ora,aa,aaa, …And the last thing: Groups
When you want to keep the value appart from the entire match, so you can do anything with it, you can use groups:
(something).