Is there a regex to replace the outer part of a string while keeping the inner part?
before:
${person.dog.name}
after:
<c:out value="${person.dog.name}"/>
I need to use it in Eclipse editor, and the inner part changes.
This can be useful too:
Search: \$\{(.*?)\}
Replace:\$\{fn:escapeXml\($1\)\}
${person.dog.name}
become
${fn:escapeXml(person.dog.name)}
Find expression with:
and replace expression will be:
To find
${person.dog.name}
with<c:out value="${person.dog.name}"/>
in Eclipse editor!Edit:
Be careful while using it, because
<c:if test="${foo}">
will end up like<c:if test="<c:out value="${foo}" />">
Just capture the entire string with
^(.*)$
and then use in the replace function use a back reference like<c:out value="$1"/>
where the$1
is the backreferenceIn eclipse see link. You'd put
^(.*)$
intofind
,<c:out value="$1"/>
into replace. select regular expressions, click find and replace.If you're looking to capture all the
${foo}
with<c:out value="${foo}"/>?
in some larger text then you'll have to use the regex([$]{foo})
to find all the desired text then use<c:out value=\"$1\"/>
in the replace field.