On Saturday, September 10, 2016 at 4:12:17 AM UTC+1, Doug OLeary wrote:
> Hey;
> 
> Long term perl ahderent finally making the leap to python.  From my reading, 
> python, for the most part, uses perl regex.. except, I can't seem to make it 
> work...
> 
> I have a txt file from which I can grab specific titles via a perl one-liner:
> 
> $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables
> 1. ${title1}
> 2. ${title2}
> "3. ${title3}",,,
> 4. one more title
> 5. nuther title
> 6. and so on...,,
> ...
> 25. last title
> 
> I can't seem to get the same titles to appear using python:
> 
> 
> $ python -V
> Python 3.5.2
> $ python
> Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import os
> >>> import re
> >>> with open('tables','rt') as f:
>       data = f.read()
> 
> printing data results in the output I would expect..
> 
> Trying to compile a regex and display the results does not show the same 
> results I get from perl.  
> 
> >>> regex = r'^("?)[1-9]*\.'
> >>> re.search(regex, data)
> >>>
> 
> >>> p = re.compile(r'^("?)[1-9]*\.')
> >>> p
> re.compile('^("?)[1-9]*\\.')
> >>> p.findall(data)
> 
> I've tried any number of options shown on the net all with the same result.  
> Can someone point out what I'm messing up?
> 
> Thanks
> 
> Doug

I'm no regex expert but would this third party module 
https://pypi.python.org/pypi/regex help?

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to