1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python equivalent of java-regex Pattern.quote ( \Q and \E )? [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    In Java the regular expression \Q\s\E will match the literal string "\s" and not whitespace because \Q and \E quote the part of the regex inside them. For quoting a whole string conveniently and with care of the edge-case that the string contains an \E, the Pattern.quote-method exists.

    Java even has another way of achieving 'regex-methods without regex-special-characters', and that is to pass Pattern.Literal as a flag when compiling the regex.

    With python I can not find any equivalent of Pattern.quote nor do I find an equivalent for the underlying mechanism of \Q and \E. I also see no equivalent of the Pattern.Literal-flag. What are my options here?

    Continue reading...

Compartilhe esta Página