Difference in `parse` and `search`
See original GitHub issueI know that parse.search
should be used to match a pattern at any position in the string whereas parse.parse
has to match the string exactly.
The following issue came up some days ago in the radish project: https://github.com/radish-bdd/radish/issues/106 Especially this comment might be interesting: https://github.com/radish-bdd/radish/issues/106#issuecomment-299503624
However, this gives as interesting outcome:
>>> patt = parse.compile('I have a {}') >>> patt.search('I have a apple') <Result ('a',) {}> >>> patt.parse('I have a apple') <Result ('apple',) {}>
and
>>> patt = parse.compile('I {} a {}') >>> patt.parse('I have a apple') <Result ('have', 'apple') {}> >>> patt.search('I have a apple') <Result ('have', 'a') {}>
As you can see search
and parse
are giving different results. In this example it indeed be possible to just use parse
- but in a lot of cases we use this library for is not.
Is this intended behavior?
Adding @rscrimojr
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
search:parse — MarkLogic 9 Product Documentation
This function parses query text according to given options and returns the appropriate cts:query XML. If the query string to be parsed does...
Read more >A Guide To Parsing: Algorithms And Terminology
Parsing allows to transform data in a way that can be understood by a specific software. The obvious example are programs: they are...
Read more >Parse Operators | Sumo Logic Docs
Parse operators allow you to extract fields from log messages within a query manually and on an ad-hoc basis. For best practices use...
Read more >difference between reading and parsing - CodeRanch
Reading a file simply has the aim of transferring its contents from file into memory. Parsing attempts to find some kind of meaning...
Read more >How do parse modes work with different backends? - Drupal
Furthermore, the Database backend ignores phrases completely, searching for just the individual words, so this highlighting process is more ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve not had a chance to investigate.
On 7 May 2017 at 18:41, Timo Furrer notifications@github.com wrote:
The lazy match is often necessary so parse will match the minimum necessary to match the string. In hindsight, saying that the example provided is buggy was incorrect of me - it’s doing exactly what was requested (ambiguously) of it. The library has no way to know how long the second element should be when searching through a text for a match (where the text could be very long indeed). I think I’m going to close this because there’s really no action I believe I can take.