Any way to get raw regex literal from RegexBuilder?

We can convert a regex literal to a RegexBuilder pattern using Xcode, but is there way to access the generated regex literal from a RegexBuilder pattern?

This would be useful in figuring out how different RegexBuilder components map to the original regex string syntax.

For example, I'm trying to understand how the Optionally component works and being able to see the string it generates would help me figure out what is happening behind the scenes.

RegexBuilder does not generate textual regex internally, and there are some features that could not be represented in a textual regex. This feature is in the plans though, as mentioned here SE-0351: Regex Builder DSL - #13 by rxwei

I am learning RegexBuilder features by feeding textual regexes to the interactive generator of mine here RegexBuilder Generator


@paiv already said this in his answer, but I want to spell it out more clearly: there is no "generated textual regex" from a builder. "Classic" regexes and builders are two source representations of programs to be executed by the matching engine. Both the classic regex representation and the builder are consumed by the Swift compiler to produce an intermediate representation of the program. The actual programs supported by the matching engine are a superset of what can be encoded in the two representations.


That generator is really cool! It will definitely help in learning the different types used in the builder.

I was playing in Xcode with Refactor to Regex Builder, and this was not generated correctly:

Regex {
    ChoiceOf {

... which is equivalent to /a|\d|c/, so beware.

Reported in FB10394634


Thanks for the nice bug report!