Tuna
Tuna

Reputation: 3005

replace href and url by the <c:url /> tag

I'm working on a web application using JSP and JSTL in presentation layer. When I get html from designer, my jsp file is updated as below:

...
<link rel="stylesheet" type="text/css" href="<c:url value="/fo/inc-css/normalize.css"/>" />
<link rel="stylesheet" type="text/css" href="<c:url value="/fo/inc-css/font.css"/>" />
<link rel="stylesheet" type="text/css" href="inc-css/jquery.jscrollpane.css" />
<link rel="stylesheet" type="text/css" href="inc-css/csspie.css" />
...
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="inc-js/plugins.js" type="text/javascript"></script>
<script src="inc-js/plugins/jquery.fitvids.js" type="text/javascript"></script>
<script src="inc-js/plugins/jquery.bxslider.min.js" type="text/javascript"></script>
...
<h1><a href="/" title="Home Page">Home Page</a></h1>
...
<ul>
    <li><a href="#" title="LOG OUT">Log out</a></li>
    <li><a href="#" title="My Profile">My Profile</a></li>
    <li><a href="#" title="Help">Help</a></li>
    <li><a href="#" title="Contact Us">Contact Us</a></li>
</ul>
...

There is many href/url without <c:url />(I don't show the whole file because it is very long). I want to replace all href/url with the <c:url /> tag but #, / and full url. For example

href="inc-css/jquery.jscrollpane.css"  

should become

href="<c:url value="/fo/inc-css/jquery.jscrollpane.css" />"

Can anyone suggest me some patterns for searching/replacing in Notepad++ or Eclipse?

Upvotes: 1

Views: 1611

Answers (2)

Jerry
Jerry

Reputation: 71538

Notepad++:

You could use this in find:

href="([^"<]{2,}")

And in replace, you can use:

href="<c:url value="/fo/\1 />"
                        ^^

The ^^ indicate where the captured group is being inserted.

EDIT: To match both href and src, you will use this:

(href|src)="([^"<]{2,}")

And replace:

\1="<c:url value="/fo/\2 />"

Upvotes: 1

Nate from Kalamazoo
Nate from Kalamazoo

Reputation: 436

In Eclipse you could

Find href="([^#][^\"]+)"

Replace with href="<c:url value="$1" />"

Although I think because you have quotes within quotes, you may be better off doing

Replace with href="<c:url value='$1' />"

Upvotes: 0

Related Questions