Giter VIP home page Giter VIP logo

pregexp's People

Contributors

ds26gte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pregexp's Issues

Matching with optional subexpression, time increases exponentially with length of input string when match fails

I'm working with the current (2020-01-29) version of pregexp. It looks like the time required to match an input which doesn't match the regex increases exponentially with the length of the input string, when there is an optional subexpression in the pattern.

I am working with SBCL 2.1.6. I have edited the console log for clarity.

First example. PREGEXP-MATCH returns quickly when the input matches.

* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaa | bbbbb | ccccc | foobar" 0 NIL))
Evaluation took:
  0.000000 seconds of total run time (0.000000 user, 0.000000 system)
("aaaaa | bbbbb | ccccc | foobar" "foobar")

Additional examples. PREGEXP-MATCH takes a long time when the match fails, and time approximately doubles with each additional input character.

* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaa | bbbbb | ccccc | ddddd" 0 NIL))
Evaluation took:
  0.416000 seconds of total run time (0.404000 user, 0.012000 system)
NIL
  
* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaa | bbbbb | ccccc | dddddd" 0 NIL))
Evaluation took:
  0.784000 seconds of total run time (0.780000 user, 0.004000 system)
NIL
  
* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaa | bbbbb | cccccc | dddddd" 0 NIL))
Evaluation took:
  1.556000 seconds of total run time (1.540000 user, 0.016000 system)
NIL
  
* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaa | bbbbbb | cccccc | dddddd" 0 NIL))
Evaluation took:
  3.112000 seconds of total run time (3.044000 user, 0.068000 system)
NIL
  
* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaaa | bbbbbb | cccccc | dddddd" 0 NIL))
Evaluation took:
  6.108000 seconds of total run time (6.068000 user, 0.040000 system)
NIL
  
* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaaa | bbbbbb | cccccc | ddddddd" 0 NIL))
Evaluation took:
  11.864000 seconds of total run time (11.736000 user, 0.128000 system)
NIL
  
* (time (PREGEXP-MATCH "([a-z][a-z]* *\\|* *)*foobar" "aaaaaa | bbbbbb | ccccccc | ddddddd" 0 NIL))
Evaluation took:
  23.696000 seconds of total run time (23.480000 user, 0.216000 system)
NIL

lookbehind doesn't process newlines or respect start position

The regular expression '.*(?<!/)'.*' looks for strings with single quotes that have an internal single quote not preceded by a slash.

The following works as expected:

> (pregexp-match "'.*(?<!/)'.*'" "'/'fine'")
#f

Why does this happen?

> (pregexp-match "'.*(?<!/)'.*'" "\n'/'fine'")
("'/'fine'")

But it's fine with a non-newline:

> (pregexp-match "'.*(?<!/)'.*'" "\r'/'fine'")
#f

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.