Questions tagged [rawstring]

A string literal which would be processed without any language-specific interpretation, avoiding the need of escaping characters and thus providing more legible strings.

Raw strings are particularly useful when a common character needs to be escaped, notably in regular expressions (nested as string literals), where backslash \ is widely used, and in DOS/Windows paths, where backslash is used as a path separator.

143 questions
0
votes
1 answer

python : how to cast or convert string in a variable into raw

x=''' print '\tone \'piece\' of \"metal\" with \\sharp\\ edge ' print '\nthanks' ''' exec(x) I have a string variable (x) and i want to use exec() to print it out correctly. If i have access to the variable i can directly use r' and problem solved,…
andio
  • 1,574
  • 9
  • 26
  • 45
0
votes
0 answers

Kotlin raw string throws blank error

I'm creating a gradle plugin using kotlin and I am inserting some ascii art. Rather than trying to escape a load of backslashes, I decided to use raw strings but now I'm encountering bizarre nameless errors whenever my line contains 2 vertical…
ddowney
  • 1
  • 1
0
votes
1 answer

How to reflect if a raw or normal string was used?

I have a configuration file where users can provide regular expressions to match against words, e.g. wordlist = ["is", r"\b(and)\b"] The problem is: if a user provides "is", this will also match against "This" -- which is not what I want. The…
duesee
  • 141
  • 1
  • 9
0
votes
2 answers

Raw Strings in Code::Blocks?

I am reading a directory from a file, for example I loaded this "Main\Characters\Player.xxx", so I want to create the folders Main and Characters. I tried using this method (after removing Player.xxx from the string)": string syntax = "md…
thethiny
  • 1,125
  • 1
  • 10
  • 26
0
votes
0 answers

Regular Expression tested but not working

I have a fairly simple regular expression pattern that I'm trying to match with some raw string literals. I've tested the pattern here (https://regex101.com/r/xT6xU8/2) and it works perfectly, but in my code (snippet below), it doesn't work. import…
Try431
  • 217
  • 6
  • 16
0
votes
1 answer

Scala convert a string to raw

I know raw String can be declared as: val foo: String = """foo""" or val foo: String = raw"foo" However, if I have a string type val, how can I convert it to raw? For example: // val toBeMatched = "line1: foobarfoo\nline2: lol" def…
SexyNerd
  • 1,084
  • 2
  • 12
  • 21
-1
votes
2 answers

Include newline in one-line raw string literal?

Constructing a string for bulk posting for the purposes of Elasticsearch, I need to conform to a particular newline formatting. A raw string literal like this does the job: let json = format!(r#"{{"index":{{"_id":"{}"}}}} {} "#, *num,…
mike rodent
  • 14,126
  • 11
  • 103
  • 157
-1
votes
1 answer

How can I remove unterminated string while fetching details from raw string

While writing code to search for USA phone number patterns which may or may not start with first 3 numbers like (415) or 415 (e.g full number like (415)-555-1234 ) encountered the error untermianted subpattern. Code :- #! python3 import re,…
-1
votes
4 answers

i am trying to use raw string concept but finding error

program: d=r'he said,'let's python.'' print(d) output: File "", line 1 d=r'he said,'let's python.'' ^ SyntaxError: invalid syntax
-1
votes
1 answer

Python Converts the backslash followed by numbers into Unicode

I have a string which is a Windows path returned by another function. The function returns the path with a single backslash within it. Here I can't using raw string conversion to a variable. re.escape(path) does not work either.…
Ritesh
  • 314
  • 7
  • 19
-1
votes
1 answer

Python3: How can I return a raw string containing both " and '. I can't figure it out even with raw string (r'') and escape character (\)

I have recently started python and am having a frustratingly hard time trying to figure out how to print a raw string containing both ' and " characters. Even with various combinations of r'' and \ I cannot get python to return the literal string…
massey95
  • 11
  • 3
-1
votes
2 answers

"[Errno 13] Permission denied" on PIL Image.open if path and filename are not given in a raw string

I am dealing with an issue on the Image.open() function from PIL in Python. I try to open an image from a path / folder saved on a string: path_and_filename = "c:\tmp\test.jpeg" image = Image.open(path_and_filename) Then I get the error: fp =…
Dunick
  • 111
  • 1
  • 10
-1
votes
2 answers

How to handle \2 in the Windows path with Python?

I run an external function that returns a Windows path to a file on disk as a string (part of the string: Error details are at "C:\Users\ADMINI~1\AppData\Local\Temp\2\BuildErrors.txt" Succeeded So, I load the result returned into a string…
Alex Tereshenkov
  • 3,340
  • 8
  • 36
  • 61
-1
votes
3 answers

Raw string for variables in python?

I have seen several similar posts on this but nothing has solved my problem. I am reading a list of numbers with backslashes and writing them to a .csv. Obviously the backslashes are causing problems. addr = "6253\342\200\2236387" with…
Joe
  • 59
  • 1
  • 10
-2
votes
1 answer

re.search ingores "+" sign when adding a "r" for raw string

import re email = input("What's your email? ").strip() if re.search(r"^.+@.+\.edu$", email): print("Valid") else: print("Invalid") (FYI: I'm a total beginner when it comes to python) I'm learning with the help of HarvardX CS50P and have…
oriasirmi
  • 1
  • 1
1 2 3
9
10