# SE-0355: Regex Syntax and Runtime Construction

**URL:** <https://forums.swift.org/t/se-0355-regex-syntax-and-runtime-construction/57038>\
**Category:** Proposal Reviews\
**Created:** [April 28, 2022, 2:24pm UTC](https://forums.swift.org/t/se-0355-regex-syntax-and-runtime-construction/57038 "2022-04-28T14:24:51Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Michael\_Ilseman](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/michael_ilseman/32/44640_2.png) [@Michael\_Ilseman](https://forums.swift.org/u/Michael_Ilseman)\
**Post date:** [May 6, 2022, 7:04pm UTC](https://forums.swift.org/t/se-0355-regex-syntax-and-runtime-construction/57038/15 "2022-05-06T19:04:16Z")

</div>

> [@ensan-hcl](#):
>
> But hmmmm, if introducing a messy syntax is just a "linting problem", then we should introduce all proposed syntax sugars if there is no "technical" difficulties. We didn't have to have long long discussion about `if let x` syntax. If you don't like proposed syntax, you can just remove them by linter.

Beyond the strawperson argument and the strained analogy, future extensibility _is_ a technical difficulty introduced by excessive sugar. Swift is a new(ish) programming language and as such has more syntactic growth in its future. It's also a _programming language_. Regex syntax is already well established externally to the Swift project and doesn't have nearly as much syntactic growth in its future.

But you do bring up a good point though, we should consider whether a syntactic restriction on literals would allow us to make them even more appealing. There are so many more things expressible in the DSL than a literal, and we should close that gap by making literals **more** powerful. We can do this by reserving some syntax for literals specifically for future improvements.

If we can reasonably reserve non-meta-character `<` and `>` (meaning outside of named-capture syntax) inside the literals, we could use them for interpolation in the future. Any `RegexComponent` can be used in an interpolation, bringing the literals important expressive power currently only available in the builder DSL.

This would mean that `/prefix<dateParser>suffix/` would be roughly equivalent to `Regex { /prefix/ ; dateParser ; /suffix/ }`

This would also enable useful source tool refactorings like converting portions of a DSL back into a literal for brevity. This is only possible to a very limited extent currently, but interpolation would open it up to the broader case.

We could also reserve `<{ ... }>` for an in-line closure that receives something from the engine (e.g. current capture state or a direct interface to the engine itself), etc.

If we can't reserve plain '\<' and '\>', we should definitely still reserve `<{ ... }>`.

Thank you for the inspiration!

---

_[View the full topic](https://forums.swift.org/t/se-0355-regex-syntax-and-runtime-construction/57038)._
