Comments (3)
The only solution I can think of is to do this copy and alter regex.py and
_regex_code.py:
1. Copy regex.py to regex_v1.py
2. Copy _regex_core.py to_regex_core_v1.py
3. In regex_v1.py, rename all "_regex_core" to "_regex_core_v1"
4. In regex_v1.py, change "DEFAULT_VERSION = VERSION0" to "DEFAULT_VERSION =
VERSION1"
Original comment by [email protected]
on 18 Sep 2011 at 12:04
from mrab-regex-hg.
Thanks, this is simple enough to be handled individually.
Just the following quick and dirty code seems to work:
########### make_regex_v1.py #### python Lib folder ###########
#! Python
# -*- coding: utf-8 -*-
# Duplicate the py files of the regex module changing the default behaviour to
VERSION1.
with open("_regex_core.py") as reg_c_orig, open("_regex_core_v1.py", "w") as
reg_c_v1:
reg_c_v1.write(reg_c_orig.read())
with open("regex.py") as reg_orig, open("regex_v1.py", "w") as reg_v1:
reg_src = unicode(reg_orig.read(), "utf-8")
reg_src = reg_src.replace("_regex_core", "_regex_core_v1")
reg_src = reg_src.replace("DEFAULT_VERSION = VERSION0", "DEFAULT_VERSION = VERSION1")
reg_v1.write(reg_src.encode("utf-8"))
################################################
>>> import regex
>>> import regex_v1
>>> regex.findall(r"[\w--b]", "abc")
['a', 'b', 'c']
>>> regex_v1.findall(r"[\w--b]", "abc")
['a', 'c']
>>> regex.findall(r"(?V1)[\w--b]", "abc")
['a', 'c']
>>> regex_v1.findall(r"(?V0)[\w--b]", "abc")
['a', 'b', 'c']
>>>
######################
Just as an aside, it turns out, that the V0 behaviour isn't the same as re, as
the latter throws errors on some patterns utilising the set operators:
>>> re.findall(r"[\w--b]", "abc")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python27\lib\re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
File "C:\Python27\lib\re.py", line 244, in _compile
raise error, v # invalid expression
error: bad character range
>>>
I just mention it in case it would matter for inclusion of the regex to the
standard library, but I believe, it shouldn't be relevant (There is hardly some
working code relying on some pattern being invalid - only such code would be
"disturbed" if that pattern would work and could match something in regex.)
Also, this one isn't a matter of nested flags but the handling of \w in the set
anyway.
Regards,
vbr
Original comment by [email protected]
on 18 Sep 2011 at 8:50
from mrab-regex-hg.
Original comment by [email protected]
on 10 Jul 2012 at 4:52
- Changed state: Done
from mrab-regex-hg.
Related Issues (20)
- Need diagnostic info in re.error HOT 3
- Missing setup.py regex-2014.08.28 tar.gz HOT 1
- K | C are note recognized in fuzzy search when followed by any symbol HOT 1
- Why this code is drastically slower than re? HOT 5
- regex.DEBUG fires only once HOT 1
- Failed debugging output of incomplete range HOT 3
- Failed debugging output of incomplete range HOT 1
- Failed debugging output of incomplete range HOT 1
- Please add a LICENSE file to the package HOT 5
- Reference to entire match (\g<0>) in Pattern.sub() doesn't work as of 2014.09.22 release. HOT 1
- regex module cannot be found HOT 3
- Infinite loop is found HOT 2
- unicode properties containing whitespace; unknown properties HOT 4
- escape function bug HOT 4
- Punctuation characters not matched using [:punct:] HOT 4
- nested sets behaviour HOT 1
- index out of range on null property \p{} HOT 1
- support for captures() in expandf() HOT 2
- Add timeout detection? HOT 1
- PyPy Support (with patch) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mrab-regex-hg.