When are double quotes required to create a KDB/q symbol? - kdb

Normally, for simple character strings, a leading backtick does the trick.
Example: `abc
However, if the string has some special characters, such as space, this will not work.
Example: `$"abc def"
Example: `$"BAT-3Kn.BK"
What are the rules when $"" is required?

Simple syntax for symbols can be used when the symbol consists of alphanumeric characters, dots (.), colons (:), and (non-leading) underscores (_). In addition, slashes (/) are allowed when there is a colon before it. Everything else requires the `$"" syntax.

The book 'Q for mortals', which is available online, has a section discussing datatypes. For symbols it states:
A symbol can include arbitrary text, including text that cannot be
directly entered from the console – e.g., embedded blanks and special
characters such as back-tick. You can manufacture a symbol from any
text by casting the corresponding list of char to a symbol. (You will
need to escape special characters into the string.) See §6.1.5 for
more on casting.
q)`$"A symbol with blanks and `"
`A symbol with blanks and `
The essential takeaway here is that converting a string to a symbol is required when special characters are involved. In the examples you have given both space " " and hyphen "-" are characters that cannot be directly placed into a symbol type.

Related

Difficulty forming a regular expression

I'm trying to check a string to make sure that it only contains lowercase and uppercased letters, the digits 0-9, underscores, dashes and periods.
The regular expression I've been using for letter, numbers, underscores and dashes works fine and is this:
"[^a-zA-Z0-9_-]"
I'm having difficulty adding the check for spaces and periods though.
I've tried:
"[^a-zA-Z0-9_- ]" (added a space after the dash)
"[^a-zA-Z0-9_-\s\.]" (trying to escape a white space character)
I've also tried putting the \s and \. outside of the main block and also in blocks of their own.
Thanks for any advice.
A hyphen (representing the character) must be at the beginning or at the end of the (negating) character class.
Inside a character class the period is a normal character, it doesn't need to be escaped.
let pattern = "[^a-zA-Z0-9_. -]+"
Be careful about adding characters which have a special meaning: you forgot the hyphen.
I think that this is what you are looking for:
"[\^ a-zA-Z0-9_,\.\-]"

Perl regex presumably removing non ASCII characters

I found a code with regex where it is claimed that it strips the text of any non-ASCII characters.
The code is written in Perl and the part of code that does it is:
$sentence =~ tr/\000-\011\013-\014\016-\037\041-\055\173-\377//d;
I want to understand how this regex works and in order to do this I have used regexr. I found out that \000, \011, \013, \014, \016, \037, \041, \055, \173, \377 mean separate characters as NULL, TAB, VERTICAL TAB ... But I still do not get why "-" symbols are used in the regex. Do they really mean "dash symbol" as shown in regexr or something else? Is this regex really suited for deleting non-ASCII characters?
This isn't really a regex. The dash indicates a character range, like inside a regex character class [a-z].
The expression deletes some ASCII characters, too (mainly whitespace) and spares a range of characters which are not ASCII; the full ASCII range would simply be \000-\177.
To be explicit, the d flag says to delete any characters not between the first pair of slashes. See further the documentation.

Regular expression in Swift to validate Cardholder name

I am looking for a regular expression to use in Swift to validate cardholder name for a credit card. I am looking for a regEx which:
Has minimum 2 and maximum of 26 characters
Accept dashes (-) and apostrophes (') only and no other special character
Capital and small alphabets and no numbers.
Should not start with a blank space.
I was using this
"^[^-\\s][\\p{L}\\-'\\s]{2,26}$"
but it only accepts dash (-) no apostrophe (')
try with this regex
(?<! )[-a-zA-Z' ]{2,26}
see here
https://regex101.com/r/0UVvR1/1
Guessing from your description, this is what you are looking for:
^[\p{L}'-][\p{L}' -]{1,25}$
Demo
A few remarks:
you propbably do not want to allow all possible white-space chars [\r\n\t\f\v ] but just spaces.
you have to adjust the allowed lenght of the second string if you add a 1st group that does not include space and dash (since that group contributs an additional character).
with \p{L} you allow any kind of letter from any language (which is good); otherwise use [a-zA-z] if just want to allow the regular (ASCII) alphabet.
PS: Do not forget to escape the pattern properly: "^[\\p{L}'][\\p{L}' -]{1,25}$"

What is difference between \ and \\

I have an embedded word document in my worksheet, names "Rec1"
The fields code are same as below:
{LINK Excel.SheetMacroEnabled.12 "C:\\Documents and Settings\\user\\Desktop\\Salaries\\StaffSalaries.xlsm" مالي!R2C13 \a \f 4 \r \* MERGEFORMAT}
What is the different and using "\ \" (double BackSlash) character with "\" one?
Word field codes originate in the C programming language. In that language, the backslash is used to indicate what in Office are called "switches" (like parameters). You see this a lot in command-lines, as well.
So in the LINK field you show us, \a, \f 4, \r and * Mergeformat are telling Word how to manage the field code (more info at https://support.office.com/en-us/article/field-codes-link-field-09422d50-cde0-4b77-bca7-6a8b8e2cddbd?ui=en-US&rs=en-US&ad=US).
\a tells the field it should update automatically
\f 4 tells Word to maintain Excel's original formatting
\r instructs Word to use RTF conversion for displaying the content
* are formatting switches, in this case, manually applied formatting should be retained when the field is updated
Because a single backslash denotes a switch, when you want to pass a literal backslash you need to double it up. This is the case for a file path, for example.
A backslash \ is often used to escape characters in many applications and programming languages. But since it's an escape character, it also needs to escape itself, if you literally mean \.
So in an environment where \ is an escape character, you need a double blackslash \\ to mean \.

Allowed characters in CSS 'content' property?

I've read that we must use Unicode values inside the content CSS property i.e. \ followed by the special character's hexadecimal number.
But what characters, other than alphanumerics, are actually allowed to be placed as is in the value of content property? (Google has no clue, hence the question.)
The rules for “escaping” characters are in the CSS 2.1 specification, clause 4.1.3 Characters and case. The special rules for quoted strings, as in content property value, are in clause 4.3.7 Strings. Within a quoted string, any character may appear as such, except for the character used to quote the string (" or '), a newline character, or a backslash character \.
The information that you must use \ escapes is thus wrong. You may use them, and may even need to use them if the character encoding of the document containing the style sheet does not let you enter all characters directly. But if the encoding is UTF-8, and is properly declared, then you can write content: '☺ Я Ω ⁴ ®'.
As far as I know, you can insert any Unicode character. (Here's a useful list of Unicode characters and their codes.)
To utilize these codes, you must escape them, like so:
U+27BA Becomes \27BA
Or, alternatively, I think you may just be able to escape the character itself:
content: '\➺';
Source: http://mathiasbynens.be/notes/css-escapes