Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: markusj on August 02, 2024, 03:53:53 AM

Title: managesieve regex escaping question
Post by: markusj on August 02, 2024, 03:53:53 AM
Hi there,

i'm wondering how to create a regex filter. I.e. if I want to filter by a simple regular expression like '.*\d$', and add it to a rule using type "regex", the following sieve rule is created:

[...]body :text :regex ".*\\d$")

So the backslash is escaped, and the meaning of the rule changed. I wanted to filter any text that ends with a digit, now I'm filtering anything that ends with backslash + 'd'.

Can someone help to create a real regex filter?

Thanks in advance.

Markus
Title: Re: managesieve regex escaping question
Post by: rcf007 on September 23, 2025, 09:48:01 AM
Hi,

/^.*[0-9]{1,}$/gmix
will filter
Lorem ipsum 012345

test here: https://regex101.com

in case backslash is needed:

/^.*\\[0-9]{1,}$/gmix
will filter
Lorem ipsum \012345

in some cases (string within a program) 4xbackslash \\\\ might be useful, see here:
https://stackoverflow.com/questions/4025482/cant-escape-the-backslash-in-a-regular-expression