Hi,
Overview
I would like to know if there is a way to determine if the string contain regex characters. (Just want to know true or false).
Questions
- What is the proper way to determine if a string contains regex characters?
- Does
Regex
/RegexComponent
help in any way to achieve this? - Or is there any other work around?
Code
let searchText = "a(.*)b"
do {
let regex = try Regex(searchText)
//Is there a way to determine if searchText contains any regex characters?
//Or should I just check if they contain the characters ., +, *, ?, ^, $, (, ), [, ], {, }, |, \
} catch {
print("Error: \(error)")
}