GithubHelp home page GithubHelp logo

Comments (2)

dlclark avatar dlclark commented on May 31, 2024 1

After more digging I've figure out the difference. In the regexp package \b is only a word boundary for simple ascii [A-Za-z0-9_] so the initial Chinese characters are not considered a word boundary. Since regexp2 (and Rust, Python, and C#) uses full unicode definition for "letter" to define \b the initial Chinese characters are considered a word boundary.

If you expand \b to the full definition ((?<!\w)(?=\w)|(?<=\w)(?!\w)) and then expand the \w to the simplified regexp package definition A-Za-z0-9_ then you end up with this regex which will make regexp2 capture similarly to regexp:

((?<![A-Za-z0-9_])(?=[A-Za-z0-9_])|(?<=[A-Za-z0-9_])(?![A-Za-z0-9_]))(((([*+\-=?^_{|}~\w])|([*+\-=?^_{|}~\w][*+\-=?^_{|}~\.\w]{0,}[*+\-=?^_{|}~\w]))[@]\w+([-.]\w+)*\.[A-Za-z]{2,8}))((?<![A-Za-z0-9_])(?=[A-Za-z0-9_])|(?<=[A-Za-z0-9_])(?![A-Za-z0-9_]))

FYI, since the above regex uses look-arounds it's not compatible with the regexp package.

from regexp2.

dlclark avatar dlclark commented on May 31, 2024

The target for this regex engine is to match .NET. In this example https://regex101.com/r/mFmrlg/1 it appears regexp2 matches C#'s behavior (and Rust and Python).

There's an RE2 option that increases compatibility with RE2 (regexp package) but it doesn't work in this case.

I'll spend a bit of time later today to see if I can understand why the difference exists, but since this is such a long regex I may not be able to figure it out. If you have a shorter regex example of the issue that'd help speed up understanding the root difference.

from regexp2.

Related Issues (20)

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.