Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Escaping straight double quotes in action regex (Read 2614 times)
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Escaping straight double quotes in action regex
Mar 19th, 2013, 12:51pm
 
TB doesn't support simple escaping of a straight double quote in String.replace() operations. But, some clever sleuthing by forum user Sumner (kudos!) shows that this sort of replacement will work:

$Text = $Text.replace("XXX","\x22")

…whereby each and every 'XXX' sub-string in $Text will be replaced with a straight double quote. I've tested this in TB v5.12.1 with a variety of character number values and indeed these work when used in either/both of .replace() inputs.

So how might this be working, if quotes can't be escaped? After some head-scratching I recalled the the two string arguments used by String.replace("search","replace") are both parsed (read by TB) as regular expressions. aTbRef tell us TB uses the BOOST regex library. Specifically, it uses the Perl syntax option, which supports the a special input \xdd as:
Quote:
"A hexadecimal escape sequence - matches the single character whose code point is 0xdd."

Thus \x22 indicates a literal straight double quote character. To work out the mapping of character-to-number, see here: important - the number you want is the one in the 'Hex' column.

Will this work in all TB action code string operations? Hard to say as this isn't minutely documented. My hunch is No, not all operators, but only those where the input is known or stated to be treated as a regular expression. If in doubt, do a small deliberate test in a discrete file before trying it on actual data of value.

Notes in aTbRef re use of patterns in inputs are as accurate as the user-based testing by myself or others has shown it. If a code is stated as using a regex input it is likely to work with the \xdd method, but not otherwise. For instance, I would expect this not to work in runCommand string arguments, though testing this $Rule:

$Text = runCommand("echo 'This \x22is\x22 text'")

gives $Text of:

This "is" text

We can tell TB is doing a regex parse of the input as if the same source string is used in Terminal, the \xdd code is unchanged.

So experiment first or for a more definitive answer I would ask directly of support, as we users can't see under the hood of the app.
Back to top
 
« Last Edit: Mar 19th, 2013, 2:40pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Escaping straight double quotes in action regex
Reply #1 - Mar 19th, 2013, 2:38pm
 
I've updated the aTbRef page about coding conventions for single/double quotes.

In addition I've linked back to that from the pages on Lists (contains, icontains,replace), runCommand() and Strings (contains, icontains, replace, split). These all use 'pattern' type inputs. There are probably others but I think those updated are the ones most likely to use the technique described.

A last thought. This is edge case stuff - not explicitly designed for so but prepared to do some testing before trying on your real data. If you hit problems, given the nature of this topic, I advise emailing support rather than asking here. Why? In this context someone likely needs to see your data and have under-the-hood access. Users don't have the latter!
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: Escaping straight double quotes in action regex
Reply #2 - Mar 19th, 2013, 5:12pm
 
This explanation and the links to aTbRef and elsewhere are very helpful.  Many thanks!
Back to top
 
 
  IP Logged
Pages: 1
Send Topic Print