Roundcube Community Forum

 

managesieve regex escaping question

Started by markusj, August 02, 2024, 03:53:53 AM

Previous topic - Next topic

markusj

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

rcf007

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