GithubHelp home page GithubHelp logo

Comments (7)

notjames avatar notjames commented on June 16, 2024 15

I don't think regular expressions should be part of the core JMESPath syntax because different programming languages have different regular expression implementations, so it wouldn't be possible to guarantee that a regular expression run using JMESPath on Python would have the exact same results on PHP or Ruby or Lua or Go.

Instead I suggest writing your own custom function that makes Python regular expressions available to your code: https://github.com/jmespath/jmespath.py/blob/0.10.0/README.rst#custom-functions

I completely disagree with this assertion. Though many languages do indeed have different implementations, I estimate 99.999% of them use a PCRE library/implementation for regexes as PCRE has become the defacto standard for regular expressions. Moreover, if every language used the rationale to defer to implement regular expressions because other languages do it differently then no language would implement them. I find myself deferring to jq 90% of the time because jp doesn't employ regular expressions.

from jmespath.jep.

simonw avatar simonw commented on June 16, 2024 7

jq is an interesting comparison here. It actually bundles the full implementation of the regular expression library (a submodule that imports Oniguruma: https://github.com/stedolan/jq/tree/master/modules) that it uses in the C implementation of the tool - then different programming languages have bindings that depend on that shared implementation: https://github.com/stedolan/jq/wiki/FAQ#language-bindings

jmespath works differently: rather than shipping a single C implementation that is shared by different languages, it encourages entirely fresh implementations in different languages with no shared code, but sharing instead a thorough set of compliance tests: https://jmespath.org/libraries.html

Tests are here: https://github.com/jmespath/jmespath.test/tree/master/tests

This approach could be used to add regular expression support, by spinning up a thorough compliance test and maybe defining a subset of regular expression syntax that must be supported in order for an implementation to pass the test.

It would be a lot of work though!

from jmespath.jep.

Harliff avatar Harliff commented on June 16, 2024 6

+1 vote for regex support!

from jmespath.jep.

simonw avatar simonw commented on June 16, 2024 3

Here's a really interesting proposal, for an interoperable subset of regular expressions: https://cabo.github.io/iregexp/draft-bormann-jsonpath-iregexp.html

It's still in early stages, but it looks like it's directly relevant to this conversation.

from jmespath.jep.

mswezey23 avatar mswezey23 commented on June 16, 2024 1

I'd be in huge support for adding regex support!

from jmespath.jep.

simonw avatar simonw commented on June 16, 2024

I don't think regular expressions should be part of the core JMESPath syntax because different programming languages have different regular expression implementations, so it wouldn't be possible to guarantee that a regular expression run using JMESPath on Python would have the exact same results on PHP or Ruby or Lua or Go.

Instead I suggest writing your own custom function that makes Python regular expressions available to your code: https://github.com/jmespath/jmespath.py/blob/0.10.0/README.rst#custom-functions

from jmespath.jep.

simonw avatar simonw commented on June 16, 2024

There's a useful comparison table of the differences between different language implementations here: https://web.archive.org/web/20130830063653/http://www.regular-expressions.info:80/refflavors.html

from jmespath.jep.

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.