escaping

Escaping XML tag contents

I have a simple CAML query like <Where><Eq><Field="FieldName"><Value Type="Text">Value text</Value></Field></Eq></Where> And I have a variable to substitute for "Value text". What's the best way to validate/escape the text that is substituted here in the .NET framework? I've done a quick web search on this problem but all what I found...

How to escape os.system() calls in Python?

When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash. I'm currently doing the following, but am sure there must be a library function for this, or at l...

How to escape < and > inside <pre> tags

I'm trying to write a blog post which includes a code segment inside a tag. The code segment includes a generic type and uses <> to define that type. This is what the segment looks like: <pre> PrimeCalc calc = new PrimeCalc(); Func<int, int> del = calc.GetNextPrime; </pre> The resulting HTML removes the <> and ends up like th...

How to escape XML content with XSL to safely output it as JSON?

How to escape XML content with XSL to safely output it as JSON? ...

How to escape text for regular expression in Java

Does Java have a built-in way to escape arbitrary text so that it can be included in a regular expression? For example, if my users enter "$5", I'd like to match that exactly rather than a "5" after the end of input. ...

How to match a single quote in sed

How to match a single quote in sed if the expression is enclosed in single quotes: sed -e '...' For example need to match this text: 'foo' ...

How do I escape a string inside javascript inside an onClick handler?

Maybe I'm just thinking about this too hard, but I'm having a problem figuring out what escaping to use on a string in some javascript inside a link's onClick handler. Example: <a href="#" onclick="SelectSurveyItem('<%itemid%>', '<%itemname%>'); return false;">Select</a> The <%itemid%> and <%itemname%> are where template substitution...

How do I escape the wildcard/asterisk character in bash?

eg. me$ FOO="BAR * BAR" me$ echo $FOO BAR file1 file2 file3 file4 BAR and using the "\" escape character: me$ FOO="BAR \* BAR" me$ echo $FOO BAR \* BAR I'm obviously doing something stupid. How do I get the output "BAR * BAR" ? ...

WPF and string formatting

Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key="whatever" Text="foo\nbar" /> </Window.Resources> Obviously I want a newline character in the MyClass.Text property, but the XAML parser constructs the object with the literal string "foo\nbar". Is there (a) a way to convince the parser to translate escape sequ...

How can i parse a comma delimited string into a list (caveat)?

I need to be able to take a string like: '''foo, bar, "one, two", three four''' into: ['foo', 'bar', 'one, two', 'three four'] I have an feeling (with hints from #python) that the solution is going to involve the shlex module. ...

PHP regex to remove multiple ?-marks

I'm having trouble coming up with the correct regex string to remove a sequence of multiple ? characters. I want to replace more than one sequential ? with a single ?, but which characters to escape...is escaping me. Example input: Is this thing on??? or what??? Desired output: Is this thing on? or what? I'm using preg_repla...

How to insert a string which contains an "&"

How can I write an insert statement which includes the & character? For example, if I wanted to insert "J&J Construction" into a column in the database. I'm not sure if it makes a difference, but I'm using Oracle 9i. ...

Using Quotes within getRuntime().exec

Hi, I'd like to invoke bash using a string as input. Something like: sh -l -c "./foo" I'd like to do this from Java. Unfortunately, when I try to invoke the command using getRuntime().exec, I get the following error: foo": -c: line 0: unexpected EOF while looking for matching `"' foo": -c: line 1: syntax error: unexp...

Pass a PHP string to a Javascript variable (including escaping newlines)

What is the easiest way to encode a PHP string for output to a Javascript variable? I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a Javascript variable. Normally, I would just construct my Javascript in a PHP file, ala: <script> var myvar = "<?php echo $myVarValue;?>"; </s...

Escaping a String from getting regex parsed in Java

In Java, suppose I have a String variable S, and I want to search for it inside of another String T, like so: if (T.matches(S)) ... (note: the above line was T.contains() until a few posts pointed out that that method does not use regexes. My bad.) But now suppose S may have unsavory characters in it. For instance, let S = "[hi"...

Escaping in a ILIKE query

Hello, I need to do a query that search for a text with 'Nome % teste \ / ' as prefix. I'm doing the query using: where "name" ILIKE 'Nome a% teste \ /%' ESCAPE 'a' (using a as scape character). There is a row that match this, but this query returns nothing. Removing the slash ('Nome % teste \'), it works. But I don't see why the sla...

Escaping ' in Access SQL

I'm trying to do a domain lookup in vba with something like this: DLookup("island", "villages", "village = '" & txtVillage & "'") This works fine until txtVillage is something like Dillon's Bay, when the apostrophe is taken to be a single quote, and I get a run-time error. I've written a trivial function that escapes single quotes - ...

Is there a way to escape a CDATA end token in xml?

I was wondering if there is any way to escape a CDATA end token ( ]]> ) within a CDATA section in an xml document. Or, more generally, if there is some escape sequence for using within a CDATA (but if it exists, I guess it'd probably only make sense to escape begin or end tokens, anyway). Basically, can you have a begin or end token em...

Extra backslashes being added in PHP

My crappy web host did some upgrades the other day and some settings have gone awry, because looking at our company's wiki (MediaWiki), every quote is being escaped with a backslashes. It's not even just data which is being posted (ie: the articles) which are affected, but also the standard MediaWiki text. eg: You\'ve followed a link...

Editing escaped code (for display)

If I escape some code because I want it to display as the actual code in html (eg for an example code snippet), save it to the database and then pull it back to the editor (an html page), it is displayed as html, as opposed to the escaped text. My problem arises when I include a textarea tag in the text because it will prematurely close...