rawstring

What are the actual uses of ES6 Raw String Access?

痞子三分冷 提交于 2019-11-27 17:12:19
问题 What are the actual uses of String.raw Raw String Access introduced in ECMAScript 6? // String.raw(callSite, ...substitutions) function quux (strings, ...values) { strings[0] === "foo\n" strings[1] === "bar" strings.raw[0] === "foo\\n" strings.raw[1] === "bar" values[0] === 42 } quux `foo\n${ 42 }bar` String.raw `foo\n${ 42 }bar` === "foo\\n42bar" I went through the below docs. http://es6-features.org/#RawStringAccess https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template

Python raw literal string

ε祈祈猫儿з 提交于 2019-11-27 14:51:06
问题 str = r'c:\path\to\folder\' # my comment IDE: Eclipse Python2.6 When the last character in the string is a backslash, it seems like it will escape the last single quote and treat my comment as part of the string. But the raw string is supposed to ignore all escape characters, right? What could be wrong? Thanks. 回答1: Raw string literals don't treat backslashes as initiating escape sequences except when the immediately-following character is the quote-character that is delimiting the literal,

Raw Strings in Java - for regex in particular

你说的曾经没有我的故事 提交于 2019-11-27 06:51:43
Is there any way to use raw strings in Java (without escape sequences)? (I'm writing a fair amount of regex code and raw strings would make my code immensely more readable) I understand that the language does not provide this directly, but is there any way to "simulate" them in any way whatsoever? No, there isn't. Generally, you would put raw strings and regexes in a properties file, but those have some escape sequence requirements too. This is a work-around if you are using eclipse. You can automatically have long blocks of text correctly multilined and special characters automatically

Does clojure have raw string?

…衆ロ難τιáo~ 提交于 2019-11-27 02:17:00
问题 In Python, I can prefix an r to a string literal (raw string) to tell the interpreter not translate special characters in the string: >>> r"abc\nsdf#$%\^" r"abc\nsdf#$%\^" Is there a way to do the same thing in Clojure? 回答1: Clojure strings are Java strings and the reader does not add anything significant to their interpretation. The reader page just says "standard Java escape characters are supported." You can escape the \ though: user> (print "abc\\nsdf#$%\\^") abc\nsdf#$%\^ This only

How to create raw string from string variable in python?

混江龙づ霸主 提交于 2019-11-26 21:18:52
问题 You create raw string from a string this way: test_file=open(r'c:\Python27\test.txt','r') How do you create a raw variable from a string variable, such as path = 'c:\Python27\test.txt' test_file=open(rpath,'r') Because I have a file path: file_path = "C:\Users\b_zz\Desktop\my_file" When I do: data_list = open(os.path.expandvars(file_path),"r").readlines() I get: Traceback (most recent call last): File "<pyshell#32>", line 1, in <module> scheduled_data_list = open(os.path.expandvars(file_path)

How to convert a “raw” string into a normal string?

ぐ巨炮叔叔 提交于 2019-11-26 21:12:25
问题 In Python, I have a string like this: '\\x89\\n' How can I decode it into a normal string like: '\x89\n' 回答1: Python 2 byte strings can be decoded with the 'string_escape' codec: raw_string.decode('string_escape') Demo: >>> '\\x89\\n'.decode('string_escape') '\x89\n' For unicode literals, use 'unicode_escape' . In Python 3, where strings are unicode strings by default, only byte strings have a .decode() method: raw_byte_string.decode('unicode_escape') If your input string is already a unicode

What exactly is a “raw string regex” and how can you use it?

久未见 提交于 2019-11-26 12:53:34
From the python documentation on regex , regarding the '\' character: The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r' . So r"\n" is a two-character string containing '\' and 'n' , while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation. What is this raw string notation? If you use a raw string format, does that mean "*" is taken as a a literal character rather than a zero-or-more indicator?

Why can&#39;t I end a raw string with a backslash? [duplicate]

耗尽温柔 提交于 2019-11-26 07:49:10
问题 This question already has an answer here: Why can't Python's raw string literals end with a single backslash? 12 answers I am confused here, even though raw strings convert every \\ to \\\\ but when this \\ appears in the end it raises error. >>> r\'so\\m\\e \\te\\xt\' \'so\\\\m\\\\e \\\\te\\\\xt\' >>> r\'so\\m\\e \\te\\xt\\\' SyntaxError: EOL while scanning string literal Update: This is now covered in Python FAQs as well: Why can’t raw strings (r-strings) end with a backslash? 回答1: You

What exactly is a “raw string regex” and how can you use it?

≯℡__Kan透↙ 提交于 2019-11-26 03:29:57
问题 From the python documentation on regex, regarding the \'\\\' character: The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with \'r\' . So r\"\\n\" is a two-character string containing \'\\\' and \'n\' , while \"\\n\" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation. What is this raw string notation? If

Why can&#39;t Python&#39;s raw string literals end with a single backslash?

ぃ、小莉子 提交于 2019-11-26 03:14:21
问题 Technically, any odd number of backslashes, as described in the documentation. >>> r\'\\\' File \"<stdin>\", line 1 r\'\\\' ^ SyntaxError: EOL while scanning string literal >>> r\'\\\\\' \'\\\\\\\\\' >>> r\'\\\\\\\' File \"<stdin>\", line 1 r\'\\\\\\\' ^ SyntaxError: EOL while scanning string literal It seems like the parser could just treat backslashes in raw strings as regular characters (isn\'t that what raw strings are all about?), but I\'m probably missing something obvious. 回答1: The