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?
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.
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.
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.
Appears that using single quotes doesn't interpret the escaped characters.
E.g.,
key1: [ 'tron' ]
key2: [ 'not/escaped/[\w-]*/.*' ]
Works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With