regex matching question
John Machin
sjmachin at lexicon.net
Sat May 19 21:47:35 EDT 2007
On 20/05/2007 10:18 AM, bullockbefriending bard wrote:
>> Instead of the "or match.group(0) != results" caper, put \Z (*not* $) at
>> the end of your pattern:
>> mobj = re.match(r"pattern\Z", results)
>> if not mobj:
>
> as the string i am matching against is coming from a command line
> argument to a script, is there any reason why i cannot get away with
> just $ given that this means that there is no way a newline could find
> its way into my string?
No way? Famous last words :-)
C:\junk>type showargs.py
import sys; print sys.argv
C:\junk>\python25\python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call('\\python25\\python showargs.py teehee\n')
['showargs.py', 'teehee\n']
0
>>>
certainly passes all my unit tests as well as
> \Z. or am i missing the point of \Z ?
>
More information about the Python-list
mailing list