Coder Social home page Coder Social logo

pyre2's Introduction

pyre2

Summary

pyre2 is a Python extension that wraps Google's RE2 regular expression library. It implements many of the features of Python's built-in re module with compatible interfaces.

New Features

  • Regexp objects have a fullmatch method that works like match, but anchors the match at both the start and the end.
  • Regexp objects have test_search, test_match, and test_fullmatch methods that work like search, match, and fullmatch, but only return True or False to indicate whether the match was successful. These methods should be faster than the full versions, especially for patterns with capturing groups.

Missing Features

  • No substitution methods.
  • No flags.
  • No split, findall, or finditer.
  • No top-level convenience functions like search and match. (Just use compile.)
  • No compile cache. (If you care enough about performance to use RE2, you probably care enough to cache your own patterns.)
  • No lastindex or lastgroup on Match objects.

Current Status

pyre2 has only received basic testing, and I am by no means a Python extension expert, so it is quite possible that it contains bugs. I'd guess the most likely are reference leaks in error cases.

RE2 doesn't build with fPIC, so I had to build it with

make CFLAGS='-fPIC -c -Wall -Wno-sign-compare -O3 -g -I.'

I also had to add it to my compiler search path when building the module with a command like

env CPPFLAGS='-I/path/to/re2' LDFLAGS='-L/path/to/re2/obj' ./setup.py build

Contact

You can file bug reports on GitHub, or email the author: David Reiss <[email protected]>.

License

See the LICENSE file for more information.

pyre2's People

Contributors

sunshowers avatar bos avatar dreiss avatar noxiouz avatar moreati avatar flarnie avatar jamesgpearce avatar adamhooper avatar SpamapS avatar jwilk avatar rla3rd avatar fim avatar

Stargazers

 avatar Guillermo González avatar  avatar  avatar Vishesh avatar Caio Jordão Carvalho avatar  avatar austinjp avatar jdhao avatar Dani avatar  avatar Md Zahangir Alam(#Mr.) avatar Yakov Till avatar Muhammad avatar Che-Nan, Kuo (Sam) avatar  avatar Alex Kosh avatar Gustavo Gawryszewski avatar Tín Đặng avatar Brett Holman avatar  avatar Seonghyeon Kim avatar Jonan CM avatar  avatar Brad Solomon avatar lilkypimp1 avatar AlexMa avatar  avatar Bruno Alla avatar Joe Nathan Abellard avatar Robley Gori avatar Vladimir Ulupov avatar Yacine avatar  avatar  avatar dbaspider avatar Adrián avatar Peter Passaro avatar maya_k avatar anand jain avatar Lester Covax avatar KexZh avatar  avatar salotz avatar  avatar yuxiaoqing avatar  avatar  avatar Ricardo Ander-Egg avatar Dimitry Slavin avatar Ezequiel Moreno avatar webcpp avatar Gábor Mihálcz avatar  avatar Benjamin M. avatar Alex Hughes avatar  avatar 孙松 avatar Mohamad  Fazeli avatar ScCcWe avatar  avatar Daniel Jones avatar Kyle Cain avatar vtheno avatar Marcos "Tarusuki" Benevides avatar Taine Zhao avatar A12 avatar Sanjay avatar ringsaturn avatar  avatar William avatar Insutanto avatar Mary avatar _Empty_ avatar Ben S avatar Anton Zalaldinov avatar ast avatar Hossein Taghi-Zadeh avatar Alexander Tikhonov avatar David Yakobovitch avatar asdas12312weq avatar Ethan Estrada avatar Sean avatar GAURAV avatar  avatar akpotter avatar Surajit Dasgupta avatar  avatar flychen50 avatar Mutalisk avatar zomy (old name: cod) avatar Yulai avatar Ivan avatar  avatar wangxiaolei avatar Timon Wong avatar Alex Chan avatar Patrick Orestes Dorneles avatar Denis Arnaud avatar Matt Stump avatar

Watchers

David Reiss avatar Ivan Kozik avatar Bryan O'Sullivan avatar Xavier Deguillard avatar Chad Austin avatar evandrix avatar Zeyi (Rice) Fan avatar Stefan Filip avatar James Cloos avatar Vikram Jha avatar akpotter avatar forschnix avatar PyHedgehog avatar yx2212 avatar xuyuandong avatar Michael Anthony avatar Mateusz Kwapich avatar Kai Zhao avatar Simon Farnsworth avatar YOLO avatar ericxu avatar Max Viking avatar duxin avatar Harvey Hunt avatar Michael Drozdovsky avatar  avatar  avatar Mark Juggurnauth-Thomas avatar Saúl Germán Gutiérrez Calderón avatar  avatar codecakes avatar Jiapeng Yang avatar Jonathan McHugh avatar Radovan Kavicky avatar  avatar  avatar Arun Sathiya avatar  avatar oscar avatar  avatar  avatar Alexandr avatar 多原紅紅(于紅紅)yuhonghong avatar

pyre2's Issues

Match misplace by 2

When the ’ (RIGHT SINGLE QUOTATION MARK ; HTML &RSQUO; HEX 0x2019 ) is in the string to search the span is displace by 2, for example:

string = "it’s your car"
regex = re2.compile('you')
match = regex.search(string)
pather_match = string[match.start():match.end()]
print(pather_match)

'ur c'

cannot build on Mac

@localhost pyre2 % make CFLAGS='-fPIC -c -Wall -Wno-sign-compare -O3 -g -I.'
python3 setup.py build
running build
running build_py
running build_ext
building '_re2' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -fPIC -c -Wall -Wno-sign-compare -O3 -g -I. -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c _re2.cc -o build/temp.macosx-10.15-x86_64-3.8/_re2.o -std=c++11
_re2.cc:211:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
PyObject_HEAD_INIT(NULL)
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/object.h:85:5: note: expanded from macro 'PyObject_HEAD_INIT'
1, type },
^~~~~~~
_re2.cc:255:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
PyObject_HEAD_INIT(NULL)
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/object.h:85:5: note: expanded from macro 'PyObject_HEAD_INIT'
1, type },
^~~~~~~
_re2.cc:299:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
PyObject_HEAD_INIT(NULL)
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/object.h:85:5: note: expanded from macro 'PyObject_HEAD_INIT'
1, type },
^~~~~~~
3 warnings generated.
clang++ -bundle -undefined dynamic_lookup -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -fPIC -c -Wall -Wno-sign-compare -O3 -g -I. build/temp.macosx-10.15-x86_64-3.8/_re2.o -L/usr/local/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/sqlite/lib -lre2 -o build/lib.macosx-10.15-x86_64-3.8/_re2.cpython-38-darwin.so
clang: warning: build/temp.macosx-10.15-x86_64-3.8/_re2.o: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lre2: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-bundle' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-fPIC' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-O3' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-g' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-I .' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/lib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/opt/[email protected]/lib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/opt/sqlite/lib' [-Wunused-command-line-argument]
python3 setup.py build_ext -i
running build_ext
building '_re2' extension
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -fPIC -c -Wall -Wno-sign-compare -O3 -g -I. -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8 -c _re2.cc -o build/temp.macosx-10.15-x86_64-3.8/_re2.o -std=c++11
_re2.cc:211:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
PyObject_HEAD_INIT(NULL)
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/object.h:85:5: note: expanded from macro 'PyObject_HEAD_INIT'
1, type },
^~~~~~~
_re2.cc:255:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
PyObject_HEAD_INIT(NULL)
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/object.h:85:5: note: expanded from macro 'PyObject_HEAD_INIT'
1, type },
^~~~~~~
_re2.cc:299:3: warning: suggest braces around initialization of subobject [-Wmissing-braces]
PyObject_HEAD_INIT(NULL)
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/[email protected]/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/object.h:85:5: note: expanded from macro 'PyObject_HEAD_INIT'
1, type },
^~~~~~~
3 warnings generated.
clang++ -bundle -undefined dynamic_lookup -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -fPIC -c -Wall -Wno-sign-compare -O3 -g -I. build/temp.macosx-10.15-x86_64-3.8/_re2.o -L/usr/local/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/sqlite/lib -lre2 -o build/lib.macosx-10.15-x86_64-3.8/_re2.cpython-38-darwin.so
clang: warning: build/temp.macosx-10.15-x86_64-3.8/_re2.o: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lre2: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-bundle' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-undefined dynamic_lookup' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-fPIC' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-O3' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-g' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-I .' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/lib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/opt/[email protected]/lib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-L/usr/local/opt/sqlite/lib' [-Wunused-command-line-argument]
error: can't copy 'build/lib.macosx-10.15-x86_64-3.8/_re2.cpython-38-darwin.so': doesn't exist or not a regular file
make: *** [build] Error 1
@localhost pyre2 %

fb-re2 compiles and installs on macos but using gives segmentation fault

While I suspect there is some specific local environment issue that produces this awful result, I think that we need to prevent it from building/installing a broken package.

pip install fb-re2
python -c "import re2; re2.compile('foo')"
[1]    99748 segmentation fault  python -c "import re2; re2.compile('foo')"

I was able to reproduce the error with both python3.6 and pyton3.7 installed using pyenv.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.