<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    On 10/6/18 7:25 AM, Ram Rachum wrote:<br>
    <blockquote type="cite"
cite="mid:CANXboVZO2RaX0FSXpmKAo63cFHzVQUsa=eya80GR52BsQjSH6A@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <div dir="ltr">"This is a regular expression problem, rather than
        a Python problem."
        <div><br>
        </div>
        <div>Do you have evidence for this assertion, except that other
          regex implementations have this limitation? Is there a regex
          specification somewhere that specifies that streams aren't
          supported? Is there a fundamental reason that streams aren't
          supported?</div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>"Can the lexing be done on a line-by-line basis?"<br>
        </div>
        <div><br>
        </div>
        <div>For my use case, it unfortunately can't.</div>
      </div>
    </blockquote>
    <br>
    You mentioned earlier that your use case doesn't have to worry about
    the "a.*b" problem.  Can you tell us more about your scenario?  How
    would the stream know it had read enough to match or not match? 
    Perhaps that same logic can be used to feed the data in chunks?<br>
    <br>
    --Ned.<br>
    <br>
    <blockquote type="cite"
cite="mid:CANXboVZO2RaX0FSXpmKAo63cFHzVQUsa=eya80GR52BsQjSH6A@mail.gmail.com"><br>
      <div class="gmail_quote">
        <div dir="ltr">On Sat, Oct 6, 2018 at 1:53 PM Jonathan Fine <<a
            href="mailto:jfine2358@gmail.com" moz-do-not-send="true">jfine2358@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Ram<br>
          <br>
          You wrote:<br>
          <br>
          > I'd like to use the re module to parse a long text file,
          1GB in size. I<br>
          > wish that the re module could parse a stream, so I
          wouldn't have to load<br>
          > the whole thing into memory. I'd like to iterate over
          matches from the<br>
          > stream without keeping the old matches and input in RAM.<br>
          <br>
          This is a regular expression problem, rather than a Python
          problem. A search for<br>
              regular expression large file<br>
          brings up some URLs that might help you, starting with<br>
          <a
href="https://stackoverflow.com/questions/23773669/grep-pattern-match-between-very-large-files-is-way-too-slow"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://stackoverflow.com/questions/23773669/grep-pattern-match-between-very-large-files-is-way-too-slow</a><br>
          <br>
          This might also be helpful<br>
          <a href="https://svn.boost.org/trac10/ticket/11776"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://svn.boost.org/trac10/ticket/11776</a><br>
          <br>
          What will work for your problem depends on the nature of the
          problem<br>
          you have. The simplest thing that might work is to iterate of
          the file<br>
          line-by-line, and use a regular expression to extract matches
          from<br>
          each line.<br>
          <br>
          In other words, something like (not tested)<br>
          <br>
             def helper(lines):<br>
                 for line in lines:<br>
                     yield from re.finditer(pattern, line)<br>
          <br>
              lines = open('my-big-file.txt')<br>
              for match in helper(lines):<br>
                  # Do your stuff here<br>
          <br>
          Parsing is not the same as lexing, see<br>
          <a href="https://en.wikipedia.org/wiki/Lexical_analysis"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://en.wikipedia.org/wiki/Lexical_analysis</a><br>
          <br>
          I suggest you use regular expressions ONLY for the lexing
          phase. If<br>
          you'd like further help, perhaps first ask yourself this. Can
          the<br>
          lexing be done on a line-by-line basis? And if not, why not?<br>
          <br>
          If line-by-line not possible, then you'll have to modify the
          helper.<br>
          At the end of each line, they'll be a residue / remainder,
          which<br>
          you'll have to bring into the next line. In other words, the
          helper<br>
          will have to record (and change) the state that exists at the
          end of<br>
          each line. A bit like the 'carry' that is used when doing long<br>
          addition.<br>
          <br>
          I hope this helps.<br>
          <br>
          -- <br>
          Jonathan<br>
          <br>
        </blockquote>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Python-ideas mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python-ideas@python.org">Python-ideas@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a>
Code of Conduct: <a class="moz-txt-link-freetext" href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>