I'd like to find all instances of the following from within a larger chunk of XML code.
<grouptool id="688" rect="20,576,456,141">
<imagetool id="689" rect="349.15241201716736,581.50668036999,111.22746781115886,132.83658787255914">
<toolstroke WIDTH="1.0" CAP="2" JOIN="2" MITER="0.0" />
<bordercolor />
<image name="head-set-md.png" type="CLIPART" size="20419" w="252" h="300" CRC="3224584205" />
</imagetool>
<rectangletool id="690" rect="20,576,455.0214592274678,141">
<toolstroke />
<toolcolor />
<fillcolor RGB="16777215" ALPHA="0" />
</rectangletool>
<texttool id="691" rect="30,584,214,31">
<toolstroke />
<toolcolor />
<font style="3" size="24" />
<Text>Got Audio Problems?</Text>
</texttool>
<texttool id="692" rect="33,667,266,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>Note: Audio problems can be caused</Text>
</texttool>
<imagetool id="693" rect="36.1785407725322,631.7913669064748,262.9012875536481,24.345323741007192">
<toolstroke WIDTH="1.0" CAP="2" JOIN="2" MITER="0.0" />
<bordercolor />
<image name="unknown.png" type="CLIPART" size="1777" w="260" h="24" CRC="2321804736" />
</imagetool>
<texttool id="694" rect="32,688,269,23">
<toolstroke />
<toolcolor />
<font style="2" size="18" />
<Text>by a weak/spotty internet connection.</Text>
</texttool>
<rectangletool id="695" rect="249.53304721030045,627.7338129496403,30.33476394849785,31.44604316546762">
<toolstroke WIDTH="4.0" />
<toolcolor RGB="52224" />
<fillcolor RGB="16777215" ALPHA="0" />
</rectangletool>
</grouptool>
The key is the rect="20,576,456,141" in the first line. Ultimately, I'll be replacing the contents of the <grouptool> tag with something else, but I only need to do that for the <grouptool> that has the property rect="20,576,456,141".
I'll be using VSCode code for this and have tried a couple things so far that have failed.
Fail #1: <grouptool\b[^>]*?\brect="20,576,456,141"(?:(?!<grouptool\b).)*</grouptool>
Fail #2: <\bgrouptool.*\brect\=\"20\,576\,456\,141\"([\s\S]*?)<\/\bgrouptool>
I hardly know anything about Regex. Please advise if you're able.
In Visual Studio Code, you can search for
(<grouptool(?:\s[^>]*)?\srect="20,576,456,141"[^>]*>)[\w\W]*?(</grouptool>)
and replace with $1New Value$2.
Details:
( - Group 1 ($1):
<grouptool - a fixed string
(?:\s[^>]*)? - an optional occurrence of a whitespace and then zero or more chars other than >
\srect="20,576,456,141" - a whitespace and a rect="20,576,456,141" string
[^>]*> - zero or more chars other than > and then a >
) - end of Group 1
[\w\W]*? - any zero or more chars, as few as possible
(</grouptool>) - Group 2 ($2): a </grouptool> string.
hy guys,
i'm trying to replace a part of string inside a property like below
<property file="build-local.properties" /> <--
<propertyregex property="destProperty" input="${sourceProperty}" regexp="${whatMatch}" replace="" global="true" />
in order to replace content of property ${sourceProperty} matching string ${whatMatch} replacing with none (in this case) and finally assign result to property ${destProperty}
Currently i'm getting ${whatMatch} from build-local.properties file and ${sourceProperty} as terminal arguments
But it doesn't work.
Where i'm wrong ??
Important notes
Changing
<propertyregex property="destProperty" input="${sourceProperty}" regexp="${whatMatch}" replace="" global="true" />
from above to
<propertyregex property="destProperty" input="${sourceProperty}" regexp="HARDCODED_STRING" replace="" global="true" />
Thanks in advance
we solved using the following format:
<propertyregex property="normalizedAppVersion" input="${appVersion}" regexp="${projectPrefix}\." replace="" casesensitive="false" />
IMPORTANTS NOTES
If you're trying to replace a text that contains a ".", you can have some problem specifying dot inside property definition. So i just using the "."
# instead "MYPACKAGE."
projectPrefix="MYPACKAGE."
regexp="${projectPrefix}\."
directly in the regexp attribute value. I don't know why but if not doesn't work for me.
Thanks BTW
We recently started to use fhir path to validate a QuestionnaireResponse.
The QuestionnaireResponse is the following
<QuestionnaireResponse xmlns="http://hl7.org/fhir">
<questionnaire>
<reference value="..." />
</questionnaire>
<status value="completed" />
<authored value="2016-02-19T05:13:42.600Z" />
<group>
<question>
<linkId value="8d0db198-f341-43f8-9dd3-9151ace66375" />
<text value="date" />
<answer>
<valueDate value="2016-02-12" />
</answer>
</question>
</group>
</QuestionnaireResponse>
I have tried the following:
QuestionnaireResponse.group.question.answer.valueDate
and the answer was:
2016-02-12
However trying the following to validate the date with a regex throws exception
QuestionnaireResponse.group.question.answer.valueDate.matches("^\d{4}-((0\d)|(1[012]))-(([012]\d)|3[01])$")
it would be great if you may give me some idea of what is the best way to evaluate a date in fhir path
This turned out to be a bug in the .NET FluentPath evaluator that is in development still (regex section).
The FHIR server should also have rejected the value as not conforming without the fhirpath expression also.
If I want to load a document into a variable, I can use
<xsl:variable name="var1" select="document('http://www.mySite.com/file1.xml')" />
=> works, I can use -
<xsl:value-of select="$var1//myNodeName"/>
but now I need to use a URL with parameter.
and the following tests do not work -
<xsl:variable name="var2" select="document('http://www.mySite.com/getfile.cgi?param1=val1¶m2=val2')" />
=> does not work - EntityRef: expecting ';'
<xsl:variable name="var2" select="document('http://www.mySite.com/getfile.cgi?param1=val1¶m2=val2')" />
=> does not work - warn for wrong URL -
http://www.mySite.com/getfile.cgi?param1=val1¶m2=val2:1:
why does it add :1: ???
My Question:
How do I replace the & entity to make the document() function work?
Update:
according to -
http://our.umbraco.org/forum/developers/xslt/5421-Ampersand-in-XSLT
the solution is to store the URL as a variable, then output it disablig output escaping.
e.g.
<xsl:variable name="test" select="http://www.mysite.com/mypage.aspx?param1=1¶m2=2" />
<xsl:value-of select="$test" disable-output-escaping="yes" />
but, how can I apply this solution with document() parameter?
Update 2:
I parse it using PHP -
<?php
Header('Content-type: text/xml');
// http://php.net/manual/en/xsltprocessor.transformtoxml.php
$xml = new DOMDocument;
$xml->load('http://www.mySite.com/devices.xml');
$xsl = new DOMDocument;
$xsl->load('mergedocs.xsl');
// Configure the transformer
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // attach the xsl rules
echo $proc->transformToXML($xml);
?>
The error I get [note the amp within the URL]:
XML Parsing Error: junk after document element
Location: http://mySite/myPhpFile.php
Line Number 2, Column 1:<b>Warning</b>: XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]:
http://siteIp/cgi-bin/getfile.cgi?p1=v1&p2=v2:1: parser error : Document is empty
in <b>/home/.../myPhpFile.php</b> on line <b>16</b><br />
Encoding the & as & is the correct approach, the URL retrieved by the processor will be the correct one with val1¶m2. I suspect the :1: isn't part of the URL but rather part of the warning message i.e. problem at ::
I was writing some build scripts for my project. I wanted a regex pattern which can match everything before a particular word. For eg: My script looks like this
Create Table ABC(
id int(50)
)
--//#UNDO
Drop table ABC
I want to match everything before --//#UNDO using nant regex task. How do I implement it??
I also want it to match everything in the file if --//#UNDO is not present in the file. I am not getting a way around
This is the pattern:
(?'str'.*?)--//#UNDO
The result will be in str.
If you just want to match the text before the string (and not the string itself) you will need to use a lookahead.
.*?(?=--//#UNDO)
Needing to specify Singleline still applies.
This would be the NAnt target:
<target name="go">
<loadfile
file="C:\foo\bar.sql"
property="content" />
<regex
pattern="(?'content'.*)--//#UNDO"
input="${content}"
options="Singleline"
failonerror="false" />
<echo message="${content}" />
</target>
Notice that property content is preset with the complete file content in case that --//#UNDO is not present in file.
This is what I ended up doing
<loadfile file="${filePathAndName}" property="file.contents" />
<property name="fileHasUndo" value="${string::index-of(file.contents, '--//#UNDO')}" />
<choose>
<when test="${fileHasUndo == '-1' }">
<echo file="${file}" append="true" message="${file.contents}" />
</when>
<otherwise>
<regex pattern="(?'sql'[\s\S]*)--\/\/#UNDO[\s\S]*" input="${file.contents}" options="Multiline"/>
<echo file="${file}" append="true" message="${sql}" />
</otherwise>
</choose>
I found the index of --//#UNDO. And depending on its presence I am doing a choose when.. Solved the problem