"Proximity" in searches

"Proximity" in searches

23
Basic UserBasic User
23

    Sep 11, 2007#1

    Is it possible to search expression A AND expression B in a proximity range? What I mean is, for example, "text A" AND "text B" in the same paragraph or in a proximity range (for example: 80 characters).
    Best regards.

    262
    MasterMaster
    262

      Sep 11, 2007#2

      Well I think these suggestions come close to what you want to achive:

      Using Perl regexp this searches for "text A" and "text B" in the same paragraph:

      text A[^\r\n]+text B
      ([^\r\n]+ equals everything but CR and LF which separates paragraphs).

      Proximity could look something like:

      text A.{1,80}text B
      (.{1,80} = any chars from 1 to 80 occurence (greedy)).

      (And remember to check "regular expressions" in the find dialog and activate Perl Regexp in the configuration)

      23
      Basic UserBasic User
      23

        Re: "Proximity" in searches

        Sep 11, 2007#3

        Thank you very much! Definitively I have to study the Perl search syntax. It's really powerful.

        236
        MasterMaster
        236

          Sep 11, 2007#4

          Very good solution. However, the "proximity" example has one problem: It will not match if the two occurences are separated by a CR/LF. As far as I know, there is no way to tell UE'S Perl regex engine to allow the dot (.) to also match newlines.

          A possible workaround could be used if there is one character that you know for certain will not turn up in your files, e.g. ÿ (ASCII 255). If that's the case, you can rework the regex to

          Code: Select all

          text A[^ÿ]{1,80}text B
          (If you also want to allow for the possibility that there are zero characters between the two texts ("textAtextB") then use * instead of + in the first regex and {0,80} instead of {1,80} in the second regex)

          HTH,
          Tim

          P.S. If anyone can think of a more elegant solution, I'd be glad to hear about it. I wonder if it's really necessary to use such an ugly trick. Maybe it would be a sensible feature request to add the option "dot matches newline"...

          23
          Basic UserBasic User
          23

            Re: "Proximity" in searches

            Sep 11, 2007#5

            It's not an ugly trick and it works perfectly!