regex matching question

Steve Holden steve at holdenweb.com
Sat May 19 21:53:00 EDT 2007


John Machin wrote:
> 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 ?
>>
The simple shell command

python prog.py "argument containing
a newline"

would suffice to reject the "no newlines" hypothesis in Unix-like systems.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
------------------ Asciimercial ---------------------
Get on the web: Blog, lens and tag your way to fame!!
holdenweb.blogspot.com        squidoo.com/pythonology
tagged items:         del.icio.us/steve.holden/python
All these services currently offer free registration!
-------------- Thank You for Reading ----------------




More information about the Python-list mailing list