question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Difference in `parse` and `search`

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
r1chardj0n3scommented, May 7, 2017

I’ve not had a chance to investigate.

On 7 May 2017 at 18:41, Timo Furrer notifications@github.com wrote:

Any idea what the problem could be?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/r1chardj0n3s/parse/issues/41#issuecomment-299690858, or mute the thread https://github.com/notifications/unsubscribe-auth/AAofRmpqtH6gsobwpi9gqXYjkqbCdjIUks5r3YPQgaJpZM4NSzCY .

0reactions
r1chardj0n3scommented, Dec 14, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found