\n","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Our declarative modeling language Rel has been expanded to include new string functionalities to better handle and manipulate string data."}]},{"type":"p","children":[{"type":"text","text":"Two new string literal forms are now supported: raw string literals and interpolation expressions inside string literals."}]},{"type":"h2","children":[{"type":"text","text":"Raw Strings"}],"id":"raw-strings"},{"type":"p","children":[{"type":"text","text":"Raw string literals are string literals that keep their contents verbatim."}]},{"type":"p","children":[{"type":"text","text":"This allows users to provide complex strings (for example, for "},{"type":"a","url":"/blog/regular-expression-matching-and-capture-groups-in-rel","title":null,"children":[{"type":"text","text":"regular expressions"}]},{"type":"text","text":") without any extra steps. No processing is applied and there is no need to escape special characters."}]},{"type":"p","children":[{"type":"text","text":"Complex strings are denoted by the "},{"type":"text","text":"raw","code":true},{"type":"text","text":" identifier, immediately followed by some amount of odd quotes. The same amount of quotes must be used to terminate the literal. Anything in between is taken as is."}]},{"type":"p","children":[{"type":"text","text":"Special characters can appear without escaping, and escaping a character simply means two characters ("},{"type":"text","text":"\\","code":true},{"type":"text","text":" and the escaped character). Any number of quotes that are less than the delimiting quotes can appear inside the literal."}]},{"type":"p","children":[{"type":"text","text":"Some examples are below."}]},{"type":"p","children":[{"type":"text","text":"Examples","bold":true}]},{"type":"p","children":[{"type":"text","text":"The empty string. Note that this is the only form allowed for empty strings. Using more quotes results in a parser error:"}]},{"type":"code_block","lang":"rel","value":"raw\"\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Using quotes without escaping:"}]},{"type":"code_block","lang":"rel","value":"raw\"\"\"say, \"hello\" now\"\"\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"No need to use triple quotes for multiline strings:"}]},{"type":"code_block","lang":"rel","value":"raw\"this is a multi \n line \ntext\n\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Leading spaces are not discarded (as would be the case in “normal” string literals):"}]},{"type":"code_block","lang":"rel","value":"raw\"\n Hello\n And bye\n\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Using multiple quotes inside the string:"}]},{"type":"code_block","lang":"rel","value":"raw\"\"\"\"\"many \"\"\"\"quotes here\"\"\"\"\"","children":[{"type":"text","text":""}]},{"type":"h2","children":[{"type":"text","text":"String Interpolation"}],"id":"string-interpolation"},{"type":"p","children":[{"type":"text","text":"Rel also now supports the arbitrary interpolation of expressions inside string literals."}]},{"type":"p","children":[{"type":"text","text":"The operator used for interpolation is "},{"type":"text","text":"%","code":true},{"type":"text","text":". As such, if the actual percent character is needed instead, it has to be escaped (or alternatively, be used in a raw string literal)."}]},{"type":"p","children":[{"type":"text","text":"The result of the interpolation is a string, so arbitrary “nesting” is allowed too, as shown in the examples below."}]},{"type":"p","children":[{"type":"text","text":"Examples","bold":true}]},{"type":"p","children":[{"type":"text","text":"Alternative to using "},{"type":"text","text":"raw\"100% success rate\"","code":true},{"type":"text","text":":"}]},{"type":"code_block","lang":"rel","value":"\"100\\% success rate\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"Interpolating values from an expression:"}]},{"type":"code_block","lang":"rel","value":"def names = \"Alice\"; \"Bob\"\ndef output = \"hello %(names)\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"If the interpolated expression is a single variable, parentheses are optional:"}]},{"type":"code_block","lang":"rel","value":"def output = \"hello %names\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"The outer string literal is interpolating an expression that itself is using string interpolation:"}]},{"type":"code_block","lang":"rel","value":"def from_id = (\"user_1\", \"Alice\"); (\"user_2\", \"Bob\")\ndef ids = 1;2;3\ndef output = \"hello %(from_id[\"user_%ids\"]) and bye\"","children":[{"type":"text","text":""}]},{"type":"p","children":[{"type":"text","text":"We’re excited to learn about how you are using Rel --- please "},{"type":"a","url":"/contact-us","title":null,"children":[{"type":"text","text":"let us know"}]},{"type":"text","text":" about any future features you’d like to see."}]}],"_content_source":{"queryId":"src/content/resources/raw-strings-and-string-interpolation.mdx","path":["resource","body"]}},"_content_source":{"queryId":"src/content/resources/raw-strings-and-string-interpolation.mdx","path":["resource"]}}},"errors":null,"query":"\n query resource($relativePath: String!) {\n resource(relativePath: $relativePath) {\n ... on Document {\n _sys {\n filename\n basename\n breadcrumbs\n path\n relativePath\n extension\n }\n id\n }\n ...ResourceParts\n }\n}\n \n fragment ResourceParts on Resource {\n __typename\n title\n description\n date\n image\n categories\n authors {\n __typename\n name\n link\n }\n seo {\n __typename\n keywords\n description\n image\n image_alt\n canonical_url\n author\n published\n modified\n language\n robots\n site_name\n content_type\n }\n body\n}\n ","variables":{"relativePath":"raw-strings-and-string-interpolation.mdx"}},"src/content/meta/meta.md":{"data":{"meta":{"_sys":{"filename":"meta","basename":"meta.md","breadcrumbs":["meta"],"path":"src/content/meta/meta.md","relativePath":"meta.md","extension":".md"},"id":"src/content/meta/meta.md","__typename":"Meta","banner":{"__typename":"MetaBanner","enabled":true,"content":{"type":"root","children":[{"type":"p","children":[{"type":"text","text":"Check out "},{"type":"a","url":"/resources/highlights-of-relationalai-at-snowflake-data-cloud-summit-2024","title":"SF summit highlights","children":[{"type":"text","text":"highlights"}]},{"type":"text","text":" of RelationalAI at "},{"type":"text","text":"Snowflake's Data Cloud Summit 2024!","bold":true}]}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","banner","content"]}},"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","banner"]}},"header":{"__typename":"MetaHeader","links":[{"__typename":"MetaHeaderLinks","text":"Product","url":"/product","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",0]}},{"__typename":"MetaHeaderLinks","text":"Company","url":"/company","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",1]}},{"__typename":"MetaHeaderLinks","text":"Docs","url":"/docs","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",2]}},{"__typename":"MetaHeaderLinks","text":"Resources","url":"/resources/all/1","style":"default","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",3]}},{"__typename":"MetaHeaderLinks","text":"Get Started","url":"/get-started","style":"cta","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header","links",4]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","header"]}},"footer":{"__typename":"MetaFooter","sections":[{"__typename":"MetaFooterSections","name":"Product","links":[{"__typename":"MetaFooterSectionsLinks","text":"Overview","url":"/product","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Use Cases","url":"/product#for-problems-that-matter","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Capabilities","url":"/product#a-new-toolset","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0,"links",2]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",0]}},{"__typename":"MetaFooterSections","name":"Resources","links":[{"__typename":"MetaFooterSectionsLinks","text":"Documentation","url":"/docs/getting_started","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"News","url":"/resources/news/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Research","url":"/resources/research/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",2]}},{"__typename":"MetaFooterSectionsLinks","text":"Releases","url":"/resources/releases/1","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1,"links",3]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",1]}},{"__typename":"MetaFooterSections","name":"About Us","links":[{"__typename":"MetaFooterSectionsLinks","text":"Our Company","url":"/company","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",0]}},{"__typename":"MetaFooterSectionsLinks","text":"Contact Us","url":"/get-started","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",1]}},{"__typename":"MetaFooterSectionsLinks","text":"Careers","url":"/careers","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",2]}},{"__typename":"MetaFooterSectionsLinks","text":"Legal","url":"/legal","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",3]}},{"__typename":"MetaFooterSectionsLinks","text":"GDPR","url":"/gdpr","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",4]}},{"__typename":"MetaFooterSectionsLinks","text":"Security & Trust","url":"https://trust.relational.ai/","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2,"links",5]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","sections",2]}}],"socials":[{"__typename":"MetaFooterSocials","text":"GitHub","url":"https://github.com/RelationalAI","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/github.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",0]}},{"__typename":"MetaFooterSocials","text":"LinkedIn","url":"https://www.linkedin.com/company/relationalai/about","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/linkedin.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",1]}},{"__typename":"MetaFooterSocials","text":"Twitter","url":"https://twitter.com/relationalai","icon":"https://assets.tina.io/91d76337-e55d-4722-acb5-3106adb895b6/img/logos/twitter.png","_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer","socials",2]}}],"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta","footer"]}},"_content_source":{"queryId":"src/content/meta/meta.md","path":["meta"]}}},"errors":null,"query":"\n query meta($relativePath: String!) {\n meta(relativePath: $relativePath) {\n ... on Document {\n _sys {\n filename\n basename\n breadcrumbs\n path\n relativePath\n extension\n }\n id\n }\n ...MetaParts\n }\n}\n \n fragment MetaParts on Meta {\n __typename\n banner {\n __typename\n enabled\n content\n }\n header {\n __typename\n links {\n __typename\n text\n url\n style\n }\n }\n footer {\n __typename\n sections {\n __typename\n name\n links {\n __typename\n text\n url\n }\n }\n socials {\n __typename\n text\n url\n icon\n }\n }\n}\n ","variables":{"relativePath":"./meta.md"}}};
globalThis.tina_info = tina;
})();
Raw Strings and String Interpolation · RelationalAI
Check out highlights of RelationalAI at Snowflake's Data Cloud Summit 2024!
Our declarative modeling language Rel has been expanded to include new string functionalities to better handle and manipulate string data.
Two new string literal forms are now supported: raw string literals and interpolation expressions inside string literals.
Raw Strings
Raw string literals are string literals that keep their contents verbatim.
This allows users to provide complex strings (for example, for regular expressions) without any extra steps. No processing is applied and there is no need to escape special characters.
Complex strings are denoted by the raw identifier, immediately followed by some amount of odd quotes. The same amount of quotes must be used to terminate the literal. Anything in between is taken as is.
Special characters can appear without escaping, and escaping a character simply means two characters (\ and the escaped character). Any number of quotes that are less than the delimiting quotes can appear inside the literal.
Some examples are below.
Examples
The empty string. Note that this is the only form allowed for empty strings. Using more quotes results in a parser error:
raw""
Using quotes without escaping:
raw"""say, "hello" now"""
No need to use triple quotes for multiline strings:
raw"this is a multi
line
text
"
Leading spaces are not discarded (as would be the case in “normal” string literals):
raw"
Hello
And bye
"
Using multiple quotes inside the string:
raw"""""many """"quotes here"""""
String Interpolation
Rel also now supports the arbitrary interpolation of expressions inside string literals.
The operator used for interpolation is %. As such, if the actual percent character is needed instead, it has to be escaped (or alternatively, be used in a raw string literal).
The result of the interpolation is a string, so arbitrary “nesting” is allowed too, as shown in the examples below.