Does PureScript support verbatim string literals? Something like #"regex \s no escapes" in C#.
Alternatively is there support for regex literals as in JavaScript?
You can use triple-quote strings.
There are no regex literals AFAIK, but triple-quote strings might help there too. Example from docs:
regex """.+#.+\..+""" noFlags
Related
what is the difference between replace, replaceAll and replaceAllLiterally in Scala or Java?
replace and replaceAllLiterally are similar, and in fact the latter is deprecated. From docs:
(Since version 2.13.2) Use s.replace as an exact replacement
replaceAll on the other hand matches the string with regex and replaces it with the replacement string.
Using Python 3.4, suppose I have some data from a file, and it is literally the 6 individual characters \ u 0 0 C 0 but I need to convert it to the single unicode character \u00C0. Is there a simple way of doing that conversion? I can't find anything in the Python 3.4 Unicode documentation that seems to provide that kind of conversion, except for a complex way using exec() of an assignment statement which I'd like to avoid if possible.
Thanks.
Well, there is:
>>> b'\\u00C0'.decode('unicode-escape')
'À'
However, the unicode-escape codec is aimed at a particular format of string encoding, the Python string literal. It may produce unexpected results when faced with other escape sequences that are special in Python, such as \xC0, \n, \\ or \U000000C0 and it may not recognise other escape sequences from other string literal formats. It may also handle characters outside the Basic Multilingual Plane incorrectly (eg JSON would encode U+10000 to surrogates\uD800\uDC00).
So unless your input data really is a Python string literal shorn of its quote delimiters, this isn't the right thing to do and it'll likely produce unwanted results for some of these edge cases. There are lots of formats that use \u to signal Unicode characters; you should try to find out what format it is exactly, and use a decoder for that scheme. For example if the file is JSON, the right thing to do would be to use a JSON parser instead of trying to deal with \u/\n/\\/etc yourself.
I have a term test* and I want to treat it as string and not a wildcard of test.
How will I be able to do that in Lucene.Net. Any help???
Yes you can use a backslash to escape special characters. Both in the QueryParser and custom built searches. List of characters that require escaping can be found here.
If you're using the newer versions of Lucene.Net, you can use QueryParser.Escape("test*") to escape your search term. QueryParser.Escape() takes a string and returns the string after properly escaping all characters that are special for Lucene.
My goal is to find all "<?=" occurrences with ack. How can I do that?
ack "<?="
Doesn't work. Please tell me how can I fix escaping here?
Since ack uses Perl regular expressions, your problem stems from the fact that in Perl RegEx language, ? is a special character meaning "last match is optional". So what you are grepping for is = preceded by an optional <
So you need to escape the ? if that's just meant to be a regular character.
To escape, there are two approaches - either <\?= or <[?]=; some people find the second form of escaping (putting a special character into a character class) more readable than backslash-escape.
UPDATE As Josh Kelley graciously added in the comment, a third form of escaping is to use the \Q operator which escapes all the following special characters till \E is encountered, as follows: \Q<?=\E
Rather than trying to remember which characters have to be escaped, you can use -Q to quote everything that needs to be quoted.
ack -Q "<?="
This is the best solution if you will want to find by simple text.
(if you need not find by regular expression.)
ack "<\?="
? is a regex operator, so it needs escaping
I'm interested in using rangeOfString with some wildcard characters as part of a search string.
For example, if I have several strings like "244px" and "356px" and I want to convert all such strings to "320px". Is there a way I can use wildcards to get the desired result?
If you could use regex, you can do substitution for this pattern "[1-9][0-9]+px" to "320px"
RegexKitLite is what you want, it has a small NSString extenstion class that lets you use the built-in regex libraries easily.
Use NSNumberFormatter configured to the right pattern.