# SE-0354: Regex Literals

**URL:** <https://forums.swift.org/t/se-0354-regex-literals/57037>\
**Category:** Proposal Reviews\
**Created:** [April 28, 2022, 2:22pm UTC](https://forums.swift.org/t/se-0354-regex-literals/57037 "2022-04-28T14:22:27Z")\
**Posts on this page:** 1\
**Showing post:** 195

<div class="post-metadata">

**Author:** ![johnno1962](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johnno1962/32/6805_2.png) [@johnno1962](https://forums.swift.org/u/johnno1962)\
**Post date:** [May 7, 2022, 4:06am UTC](https://forums.swift.org/t/se-0354-regex-literals/57037/195 "2022-05-07T04:06:03Z")

</div>

But avoiding source breaks is important Doug and even one of the proposal authors conceded this was a showstopper during the pitch phase.

> [@\[Pitch #2\] Regex Literals](https://forums.swift.org/t/pitch-2-regex-literals/56736/37):
>
> > [@\[Pitch #2\] Regex Literals](https://forums.swift.org/t/pitch-2-regex-literals/56736/35):
> >
> > deprecating using `/` as a prefix operator is going to source break a innovative and significant open source project [The Composable Architecture](https://github.com/pointfreeco/swift-composable-architecture) and a good deal of client source that uses it.
> 
> IMO, this is the most compelling counter-argument to the proposed `/.../` syntax.
> 
> > [@\[Pitch #2\] Regex Literals](https://forums.swift.org/t/pitch-2-regex-literals/56736/35):
> >
> > I'm sure however if a way could be found to include `\` in the characters that can be used to define operators the TCA folk would be only too happy.
> 
> And this, or native support for case paths, would (IMO) be the most compelling workaround.

For me the strategy of managing the transition using feature flags is worse than the original problem, breaking the idea that Swift syntax is a linear progression forward. Far better not to create the problem in the first place no?

The "necessity" for the source break arises directly from fact the bare `/regex/` syntax _is the wrong destination_. This, is in turn is a consequence of the naïve view in my opinion it will ever be possible to contain a full range of possible regexes inside single character delimiters let alone one which is already an operator in Swift. It's as futile as trying to construct the enclosure for a tiger with secondhand chicken wire and as unlikely to end well. The result is weird escaping rules and whitespace sensitivity that needs to be documented and the occasional mis-parses that have already been mentioned.

You need a distinct introducer that is not currently part of the language, for example `#/` to switch the lexer into regex tokenising mode and a distinct terminator `/#` to cater for elements that may come up inside the regex. The #/regex/# syntax is no great beauty but fits this requirement well and also borrows from raw strings the notion that while it is essentially a string `\` escapes are passed through.

---

_[View the full topic](https://forums.swift.org/t/se-0354-regex-literals/57037)._
