Path: ...!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: ram@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Re: Correct syntax for pathological re.search() Date: 8 Oct 2024 19:57:45 GMT Organization: Stefan Ram Lines: 37 Expires: 1 Jul 2025 11:59:58 GMT Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de DFHk/+W2fCXrAqTXfJxB8wUHjoxrWAjzbV14KuD0jishGd Cancel-Lock: sha1:KR46P8/AN2MwbqBqNPSq1QCUuo8= sha256:ay8bhNBZYUAO3TmK8tRveztCt9KX41AQ1GOKnxhJCts= X-Copyright: (C) Copyright 2024 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links, and to transfer the body without this notice, but quotations of parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some services to mirror the article in the web. But the article may be kept on a Usenet archive server with only NNTP access. X-No-Html: yes Content-Language: en-US Bytes: 2304 ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted: >"\\\\chardef \\\\\\\\ = '\\\\\\\\". However, one can rewrite this as follows: "`chardef `` = '``".replace( "`", "\\"*4 ) . One can also use "repr" to find how to represent something: main.py text = input( "What do you want me to represent as a literal? " ) print( repr( text )) transcript What do you want me to represent as a literal? \\sout\{ '\\\\sout\\{' . We can use "escape" and "repr" to find how to represent a regular expression for a literal text: main.py import re text = input( "Want the literal of an re for what text? " ) print( repr( re.escape( text ))) transcript Want the literal of an re for what text? \sout{ '\\\\sout\\{' .