Fix RE in to_custom_re of text.rs

Match every single (potentially escaped) character of the string, so
they can be escaped properly.
This commit is contained in:
RumovZ 2020-11-17 15:39:54 +01:00
parent 8c02c6e205
commit 91873d68eb

View file

@ -313,9 +313,8 @@ pub(crate) fn to_re(txt: &str) -> Cow<str> {
/// Convert Anki style to RegEx using the provided wildcard. /// Convert Anki style to RegEx using the provided wildcard.
pub(crate) fn to_custom_re<'a>(txt: &'a str, wildcard: &str) -> Cow<'a, str> { pub(crate) fn to_custom_re<'a>(txt: &'a str, wildcard: &str) -> Cow<'a, str> {
// escape sequences and unescaped special characters which need conversion
lazy_static! { lazy_static! {
static ref RE: Regex = Regex::new(r"\\.|[*_]").unwrap(); static ref RE: Regex = Regex::new(r"\\?.").unwrap();
} }
RE.replace_all(&txt, |caps: &Captures| { RE.replace_all(&txt, |caps: &Captures| {
let s = &caps[0]; let s = &caps[0];