Swift RegexBuilder new syntax 2 or more spaces

117 views Asked by At

Hi I'm trying to build a regular expression builder to detect 2 or more spaces or a tab, so (let twoOrMoreSpacesOrTab = /\s{2,}|\t/)

How to build this using a Regex Builder?

I tried this but its not 100% acurate:

ChoiceOf {
    OneOrMore("  ")
    One("\t")
}

The problem here is that is trying to match multiples of 2 white spaces, and I want to consume the whole thing.

1

There are 1 answers

0
user19076664 On BEST ANSWER

This might work.

let twoOrMoreSpacesOrTab = Regex {
    ChoiceOf {
        Repeat(2...) {
            One(.whitespace)
        }
        One("\t")
    }
}