what does "$" mean in this SSI conditional statement? - ssi

I was reading about SSI here. The first code example under the section Control Directives looks like this:
<!--#if expr="${Sec_Nav}" -->
<!--#include virtual="" -->
<!--#endif -->
What does the "$" sign mean? EOF, a function, get...???
Thanks!

It is just a way to inject a variable value inside a string
<!--#if expr="${Sec_Nav}" -->
this is comparing expr to the value of Sec_Nav

Related

Invert regex match across lines

How would you invert this expression to match everything BUT the contents between the <!-- LIST --> and <!-- /LIST --> tags?
((?s)<!-- LIST -->.*?<!-- /LIST -->)
Meaning I'd like to remove everything before <!-- LIST --> and after <!-- /LIST -->
The regex you have used already matches the section between the two tags, you have to simply add the prior and following sections and use the backreference to replace all the contents with the saved group (usually the slash / is to escape also).
This is a generic regex code:
s/(?s).*(<!-- LIST -->.*?<!-- \/LIST -->).*/\1/
Implementation online here

Closing tags formatting in IntelliJ IDEA

Help needed to set-up a macro/code-formatting/code-style/reformat code where in the code I write (Coldfusion), is tag based and the ending of a tag needs to be formatted.
The CFML code formatter is not doing this. All I want is when I format my code, any tag that is closed or ends with /> without a space from its previous character(any character), needs to be spaced and closed.
Example: any code line that ends with )/> or "/> or character/> capital-letter/> or digit/> or anything/> needs to be changed to ) /> or " /> or character /> capital letter /> or digit /> or anything /> respectively.
How do I get this done?
If you are looking for an automatic conversion for <empty-tag/> to <empty-tag />, you can do that in IntelliJ preferences: Editor->Code Style->XML. Open "Other" and under "Spaces" section on the left check "In empty tag".
I don't think it's possible to configure the IntelliJ formatter to do this. You need to use Find | Replace in Path... with a regular expression.

regular expression not to allow zero

regular expression not to allow zero
it should allow 0.0000001 as value but should not allow to enter 0.
I need validator not javascript
I think all you need is this ^(?=.*[1-9])\d*\.?\d*$
But, you could get fancy and allow only a single leading zero if its before a decimal point.
^(?=.*[1-9])(?:[1-9]\d*\.?|0?\.)\d*$
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="Input is not valid."
ValidationExpression="^(?=.*[1-9])(?:[1-9]\d*\.?|0?\.)\d*$"></asp:RegularExpressionValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />
a regexp like that?
([1-9](\.[0-9]+)?)|(0\.[0-9]*[1-9])
looks like working ;-)
if you remove the braces it looks more understandable:
[1-9](\.[0-9]+)? | 0\.[0-9]*[1-9]
If you want to allow both Positive or Negative numbers but not 0:
^(-?.*[1-9])\d*\.?\d*$

XSLT with value of select in URL string

I want to combine some XSL with XML and put out the resulting HTML.
My XSl contains this line which doesnt work:
Click here
The desired output would be:
Click here
The code works when I leave out the <xsl:value-of select="row/objectid"/> part in the URL. It also works when I place the <xsl:value-of select="row/objectid"/> outside the hyperlink tag, so i KNOW the value-of-select to be correct by itself.
So I suspect that the quotes are messing things up...how can I fix this?
PS. I tried replacing " with ' as well
Your stylesheet should contain well-formed XML, so you can't include the output from value-of in an attribute. Use an attribute value template instead:
<a href="www.domain.com/account/business/get/?t=2&id={row/objectid}"
>Click here</a>
The expression in curly braces will be evaluated and replaced with its output.

How to use Perl Regex to detect <p> inside another <p>

I am trying to parse a "wrong html" to fix it using perl regex.
The wrong html is the following: <p>foo<p>bar</p>foo</p>
I would like perl regex to return me the : <p>foo<p>
I tried something like: '|(<p\b[^>]*>(?!</p>)*?<p[^>]*>)|'
with no success because I cannot repeat (?!</p>)*?
Is there a way in Perl Regex to say all charactère except the following sequence (in my case </p>)
Try something like:
<p>(?:(?!</?p>).)*</p>(?!(?:(?!</?p>).)*(<p>|$))
A quick break down:
<p>(?:(?!</?p>).)*</p>
matches <p> ... </p> that does not contain either <p> and </p>. And the part:
(?!(?:(?!</?p>).)*(<p>|$))
is "true" when looking ahead ((?! ... )) there is no <p> or the end of the input ((<p>|$)), without any <p> and </p> in between ((?:(?!</?p>).)*).
A demo:
my $txt="<p>aaa aa a</p> <p>foo <p>bar</p> foo</p> <p> bb <p>x</p> bb</p>";
while($txt =~ m/(<p>(?:(?!<\/?p>).)*<\/p>)(?!(?:(?!<\/?p>).)*(<p>|$))/g) {
print "Found: $1\n";
}
prints:
Found: <p>bar</p>
Found: <p>x</p>
Note that this regex trickery only works for <p>baz</p> in the string:
<p>foo <p>bar</p> <p>baz</p> foo</p>
<p>bar</p> is not matched! After replacing <p>baz</p>, you could do a 2nd run on the input, in which case <p>bar</p> will be matched.
I concur with Andy. Parsing nontrivial HTML with regexps is a world of pain.
Have a good look at HTML::TreeBuilder::XPath and HTML::DOM for making structural changes to HTML documents.
This regexp:
<p>(?:(?!</p>).)*?<p>
when matched with
<p>foo<p>bar</p>foo</p>
results in
<p>foo<p>
If you're trying to validate HTML then consider a module like HTML::Tidy or HTML::Lint.
Perhaps Marpa::HTML would help you. Read some interesting abilities it has on the author's blog about it. The short of it is that the parser works with the interpreter (I probably am getting some of the semantics incorrect) to figure out what should be present based on what CAN be present at a certain logical place in the code.
The examples shown therein fix similar problems as you seem to be dealing with in a much more consistent way than employing regexes which will inevitably suffer from edge cases.
Marpa::HTML comes with a command-line utility, built using the module, called html_fmt. This implements a parsing engine to fix and pretty-print html. Here is an example. If 'bad.html' contains <p>foo<p>bar</p>foo</p> then html_fmt bad.html gives:
<!-- Following start tag is replacement for a missing one -->
<html>
<!-- Following start tag is replacement for a missing one -->
<head>
</head>
<!-- Preceding end tag is replacement for a missing one -->
<!-- Following start tag is replacement for a missing one -->
<body>
<p>
foo
</p>
<!-- Preceding end tag is replacement for a missing one -->
<p>
bar
</p>
foo
<!-- Next line is cruft -->
</p>
</body>
<!-- Preceding end tag is replacement for a missing one -->
</html>
<!-- Preceding end tag is replacement for a missing one -->