Using ANT I'm trying to find/replace a string with spaces and double quotes using ANT replaceregexp task.
Actual tag in xml
<ser:debug enabled="false">
Below both failed.
"<replaceregexp file="filepath" match="debug enabled="false"" replace="debug enabled="true"" byline="true" />"
And
"<replaceregexp file="filepath" match="debug\ enabled\=\"false\"" replace="debug\ enabled\=\"true\"" byline="true" />"
I'm getting this error:
Element type "replaceregexp" must be followed by either attribute specifications, ">" or "/>"
However this one works fine without any issue for a different tag...since no such special char.
<replaceregexp file="filepath" match="sql-debug-mode>true" replace="sql-debug-mode>false" byline="true" />
have also tried surrounding with ' single quote...that worked – enthuguy
I need to replace dir="EAR" with "${stage.prj.dir}EAR"
This works for me
<replaceregexp file="${stage.prj.dir}/LMS_HOME/EAR/ExtLib/jar_replace.xml"
match=""EAR""
replace=""${stage.prj.dir}EAR""
byline="true"/>
Related
I'm using Intellij and I want to search for XML attributes.
For example this XML line:
<img src="madonna.jpg" alt='Foligno Madonna, by Raphael' />
I want to search my project for any other instances of this line:
<img src="BLABLALBA" alt='BLABLALBA' />
I tried using this regular expression : src="\W" but no results was found.
Any help appriciated.
Try Structural Search & Replace (Edit | Find | Search Structurally...). Use the following pattern:
<img src="$A$" alt="$B$" />
And set the file type to XML or HTML depending on what type of files you are searching.
I am trying to write a regular expression in Java to remove all from start of <select> and end of select </> tag as shown below. I wrote a regular expression to remove everything starting from <start> tag with empty as below. The issue is it's removing everything as expected except in the fourth line, <select name="first" ... the popular. It removes everything in that line and ignores content which is in the next line, and ... president"/>. I want to include everything from start and end tag. How can I do that?
str.replaceAll(".*<start.*", "");
The actual String str has content shown below:
<select name="id" content="2454803.html"/>
<select name="nameid" content="2454803"/>
<select name="type" content="prd"/>
<select name="first" content="In 2004, Charlie, the popular
and charismatic senator , became the first president"/>
<select name="title" content="Charlie"/>
<h1>
<!--toc:insert content="checkbox" id="_1_0"/>-->
</h1>
<p class="tocline">Table of Contents</p>
According to the Java documentation, at Pattern.html#lt:
The regular expression.matches any character except a line terminator unless theDOTALLflag is specified.
A line terminator meaning:
A newline (line feed) character ('\n'),
A carriage-return character followed immediately by a newline character ("\r\n"),
A standalone carriage-return character ('\r'),
A next-line character ('\u0085'),
A line-separator character ('\u2028'), or
A paragraph-separator character ('\u2029).
The easiest way to specify the DOTALL flag is by adding (?s) to the beginning of the regex. There also need to be a few more changes to accommodate this flag, so the final regex would be (?s)<select.*?>\r?\n?, applied like
str.replaceAll("(?s)<select.*?>\\r?\\n?", "");
Demonstration here: http://regex101.com/r/bW8aR7
Alternatively, you could use the regex <select[^>]*>\r?\n?, like this:
str.replaceAll("<select[^>]*>\\r?\\n?", "");
Demonstration here: http://regex101.com/r/lO6mQ6
As the comments mentioned, you really shouldn't use regex for this. However, the issue is that the dot character in regex doesn't match newlines by default. You have to include (?s) at the start of the regex to make it do so. So:
str.replaceAll("(?s)<select.*?/>", "");
I think you're statement is
str.replaceAll(".*<select.*", "");
not
str.replaceAll(".*<start.*", "");
You need to ignore everything before and after the <select
something like this will grab the tag names (anything after the <
(?<=\<)start(?=(.*))
or you could grab <start with
(?<=.)\<start(?=(.*))
I'm trying to do this in Ant:
<echo message="[44;1;37mSuccess![m" />
But it doesn't work:
BUILD FAILED
./build.xml:92: Character reference "&#
How to do it?
The 0x1B character is invalid in XML contents (Invalid Characters in XML). So you need some workaround. I would go with a javascript workaround, but I give also 2 additional solutions:
javascript
<script language="javascript">
project.setNewProperty("esc", "\u001b");
</script>
<echo>${esc}</echo>
native2ascii
If you want the output in a file, then you could first output it using java escape \u001b, then convert it using reverse Native2Ascii routine. Regardless of the selected encoding it always decodes \u sequences.
<echo file="a.enc">\u001b</echo>
<native2ascii includes="a.enc" ext=".txt" dest="${basedir}"
encoding="iso-8859-1" reverse="true" />
property file
Finally you may have the unfortunate string constant in a file:
<property file="prop.txt" />
<echo>myEsc:${myEsc}</echo>
while the prop.txt contents is:
myEsc=\u001b
Simply use CDATA :
<project>
<echo><![CDATA[
[44;1;37mSuccess![m
]]>
</echo>
</project>
& is a special character in ant, so you should replace it with '
<echo message="[44;1;37mSuccess![m" />
How can i pass two values in a query string using LzBrowser.loadURL() in openlaszlo.
My sample code:
LzBrowser.loadURL("../modules/Index.jsp?base="+ canvas.base +" id=" + canvas.Id,"fraMain");
I am getting number Format exception:
java.lang.NumberFormatException: For input string: "1 base=1"]
Please help in solving this.
Thanks,
Raj
You should add & between two query parameters . You should write like this
LzBrowser.loadURL("../modules/Index.jsp?base="+ canvas.base +"&id=" + canvas.Id,"fraMain");
We have to provide & amp; instead of &. It worked for me.
The number format exception means, that at some point in your code the browser tries to parse a string into a number. Which version of OpenLaszlo did you use, and which runtime?
Based on the use of LzBrowser (starting with OpenLaszlo 4.1 you have to use lz.Browser instead) it seems that you are using either a 3.x or the 4.0 release of OpenLaszlo.
If you want to use the ampersand "&" within methods containing JavaScript code, the XML entity rules apply (everything which starts with an & will be treated as an XML entitity). Adding sections in your methods will let you use the & as you'd do in normal JavaScript or ActionScript code, e.g.
<canvas debug="true">
<button text="Open URL" onclick="canvas.loadUrl()" />
<attribute name="base" type="number" value="99" />
<attribute name="iD" type="number" value="10" />
<method name="loadUrl"><![CDATA[
lz.Browser.loadURL("http://www.google.com?base=" + canvas.base + "&iD=" + canvas.iD, "_blank");
]]></method>
</canvas>
Without the CDATA section, the following compiler error will be thrown:
loadurl.lzx:10:71: The reference to entity "iD" must end with the ';'
delimiter. Look for a misplaced or unescaped ampersand ('&') character
in your source code.
The described workaround of using "&" instead of "&" and no CDATA section is of course a valid option - although it reduced the readability of the JavaScript code in my eyes.
Actually there are two ways to do this, both of the following are correct:
1) Escape the special HTML characters (in this case &) by surrounding the internal code with <![CDATA[ and ]]> tags:
<method name="loadUrl">
<![CDATA[
lz.Browser.loadURL("http://www.google.com?base=" + canvas.base + "&iD=" + canvas.iD, "_blank");
]]>
</method>
2) HTML-entity encode the & character to &
<method name="loadUrl">
lz.Browser.loadURL("http://www.google.com?base=" + canvas.base + "&iD=" + canvas.iD, "_blank");
</method>
Which method you choose is up to your own preference.
I have the following code to set a userId variable:
(userId set in prior code)
<c:set var="userId" value="(Cust#${userId})" />
Which produces the following string: (Cust#${userId})
The following code works as expected, however:
<c:set var="userId" value="(Cust# ${userId})" />
displays the following string (Cust# 0001) .
Why does the '#' character before a '${string}' expression prevent the string from being evaluated? Is there a work around I could use that doesnt involve having to insert a space?
Since JSF would use:
#{userId}
To return a user Id, I would venture to guess that this is either a bug or expected behavior caused by the # sign making the parser unhappy. Just use either of:
<c:set var="userId" value="(Cust#${userId})" />
<c:set var="userId" >(Cust#${userId})</c:set>
I tested the above and it does not work. Its ouput would be:
Cust#0002 or whatever.
You can use an escape to get it to work right though. For example:
<c:set var="userId" value="(Cust\#${userId})" />
The output is:
Cust#0002