Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninterpreted strings in YAML

Tags:

python

yaml

Is there a way to have uninterpreted strings within a YAML file? My goal is to have regular expressions that contain certain escape sequences like \w. Currently, Python's YAML complains: found unknown escape character 'w'.

I know I could escape them, but this is going to obfuscate the actual regular expression. Any way around this?

like image 732
sholsapp Avatar asked Aug 02 '11 17:08

sholsapp


People also ask

Should you quote strings in YAML?

Quotes are required when the string contains special or reserved characters. The double-quoted style provides a way to express arbitrary strings, by using \ to escape characters and sequences. For instance, it is very useful when you need to embed a \n or a Unicode character in a string.

Does YAML support multiline string?

YAML supports multiline strings with block scalars, where long strings can be defined following either a > or a | (with an optional - or + ) at the end of a YAML key.

How do you do line breaks in YAML?

If you would like them to be kept as newlines, use the literal style, indicated by a pipe ( | ). If instead you want them to be replaced by spaces, use the folded style, indicated by a right angle bracket ( > ). (To get a newline using the folded style, leave a blank line by putting two newlines in.


1 Answers

Appears that using single quotes doesn't interpret the escaped characters.

E.g.,

key1: [ 'tron' ]
key2: [ 'not/escaped/[\w-]*/.*' ]

Works.

like image 53
sholsapp Avatar answered Oct 20 '22 00:10

sholsapp