Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#25 regex patterns fails when text to match contains lines

None
closed
4
2014-07-30
2012-02-16
Neil Burnett
No

I am trying to match some text that spans lines but it fails. Wrap Lines is checked. Matching with patterns that occur within a single line work.

I am using:
Find And Replace. Version 1.6 Build 201102052238

The pattern is target.+?Compile.+?exec
The text to match in files is:
<target name="Compile" depends="init">
<exec program

Discussion

  • Olivier Wehner
    Olivier Wehner
    2012-02-16

    • labels: 1170045 --> Enhancement
    • priority: 5 --> 4
    • assigned_to: nobody --> olivierwehner
     
  • Olivier Wehner
    Olivier Wehner
    2012-02-16

    Hello Neil,
    thank you very much for your input. To solve your problem, you should include a litteral line break in the search patterh like this:

    target.+Compile.+
    .+exec

    (with a litteral linebreak between the two .+ expressions)
    This finds your example text. However, it would not find the text if it was on a single like like this:

    <target name="Compile" depends="init"><exec program>

    To capture both cases you would need the following more verbose expression;

    (target.+Compile.+exec)|(target.+Compile.+
    .+exec)

    Which in turn points the fact that there are cases where one might want to disable FARs automatic line break inclusion. Actually one might want to have more controle over the "flags" governing the expression evaluation. I'll considder this for a future version.

    Hope this can help you for now.

    Olivier

     
  • Neil Burnett
    Neil Burnett
    2012-02-17

    yes that solves it. thanks very much.

    I am used to perl regex where I can do things without literal line breaks.

    I also use Regex Buddy to create and test my patterns. That product lets me select a Regex provider. Which one would allow me to create Regexes for use in FAR?

    btw, FAR is now a tool I use daily. Thank you very much for it.

     
  • Olivier Wehner
    Olivier Wehner
    2012-02-17

    Hi Neil,
    The literal line break is a feature unique to FAR. For the rest FAR uses Java regular expression syntax and I imagine there should be a provider of that name.

     

  • Anonymous
    2014-03-18

    Hello, I have good use from your program, but I've run into problems with multiline regexes in the following scenario:
    From a number of HTML files I want to remove all single- and multiline script code, both inline and included, ie.
    <script .. (code) .. </script> with (code) spanning anywhere from 0 to 40 lines.
    Considering the solution above: can it be done without a regex consisting of 40 OR'ed regexes (containing a growing number of literal newlines) ?
    Regards, Ole

     
  • Olivier Wehner
    Olivier Wehner
    2014-03-21

    Hello Ole,
    Thank you for asking this tricky question. I had this problem some time ago and didn't find a solution, even though I couldn't believe there is none. Now you made me ponder again and indeed, here it comes:
    <script (?s:.+?)</script>
    does the trick!
    This combines the "dotall" flag ?s: with the quite exotic "reluctant" quantifier +?
    Kind regards,
    Olivier

     

    • Anonymous
      2014-03-23

      Hello Olivier,
      Thank you, it solves the problem beautifully!
      I discovered that there was a single case not being caught (not mentioned in my first post), so I changed the expression (no space before first paren) - hope it's not too greedy now!

      <script(?s:.+?)</script>
      

      Best regards, Ole

       

    • Anonymous
      2014-03-23

      Hello Olivier,
      Thank you for the solution - it works fine. I discovered a simple

      <script> ... </script>
      

      pair that was not matched (and NOT described in my previous post...), so I modified your pattern and omitted the space before the (.
      Kind regards, Ole

       

  • Anonymous
    2014-03-23

    Hello Olivier,
    Thank you for the solution - it works fine. One file contained a simple

    <script> ... </script>
    

    pair that was not matched (and NOT described in my previous post...), so I modified your pattern to omit the space before the (.
    Kind regards, Ole

     
  • Olivier Wehner
    Olivier Wehner
    2014-07-01

    • labels: Enhancement --> Enhancement, multi-line, replace
    • status: pending --> closed
     


Anonymous


Cancel   Add attachments