How can I get a pattern from a Regex instance?

I'm experimenting with a new Regex type in swift 5.7 and I faced the following difficulties: I can’t find out anything about the regex itself from its instance. Even converting to a string via "\(regex)" does not give me the pattern, instead, I get a nonreadable description like "Regex(program: _StringProcessing.Regex<Swift.Substring>.Program)"
I want to make the formatting and auto-completion feature for TextField based on Regex, but for this I need to know what a regex is and its looks impossible with new regex type.

I asked this same question on stackoverflow a few months ago: How to convert a Swift 5.7 Regex back to a string? - Stack Overflow

I ended up just storing two properties -- a Regex and a String.

1 Like

In my case (and I think in most cases), if I have to store a regex string, I don't need to get regex at all. I mean it's strange to do a func like

func fieldFormat(regex: Regex<AnyRegexOutput>, regexString: String)

Instead, I do

func fieldFormat(regex: String)