Just want to clarify, suppose I want to parse a table with multiple columns each separated by “|”, I can do one of the followings and use firstMatch(of: regex) or wholeMatch(of: regex), but they assume fixed number of columns in the table. How do I deal with dynamic number of columns?
// using multi-line literal
let regex = #/
(\|)
(?<year> (.*?)(?=\|))
(\|)
(?<company1> (.*?)(?=\|))
(\|)
(?<company2> (.*?)(?=\|))
/#
// using RegexBuilder
let separator = /\|/
let regexBuilder = Regex {
separator
Capture (
OneOrMore(.any, .reluctant)
)
separator
Capture (
OneOrMore(.any, .reluctant)
)
separator
Capture (
OneOrMore(.any, .reluctant)
)
separator
}
Post
Replies
Boosts
Views
Activity
Thanks @SpaceMan!