Skip to content

Commit

Permalink
Escape regex patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
swiftyfinch committed Apr 28, 2024
1 parent dc9d497 commit 529724d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/XTreeKit/Common/RegexBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Foundation

final class RegexBuilder {
func build(wildcardsPattern: String) throws -> Regex<Substring> {
var pattern = wildcardsPattern
pattern = pattern.replacingOccurrences(of: "*", with: ".*")
pattern = pattern.replacingOccurrences(of: "?", with: ".")
var pattern = NSRegularExpression.escapedPattern(for: wildcardsPattern)
pattern = pattern.replacingOccurrences(of: "\\*", with: ".*")
pattern = pattern.replacingOccurrences(of: "\\?", with: ".")
return try Regex("^\(pattern)$")
}
}

0 comments on commit 529724d

Please sign in to comment.