Searching across multiple lines

Searching across multiple lines

2

    Aug 17, 2004#1

    I have downloaded UltraEdit, and I am assessing it for possible use. I was wondering whether it is possible to search across line breaks, i.e. a block of code.

    Sincerely,
    Joe

    38
    Basic UserBasic User
    38

      Aug 18, 2004#2

      The quick answer is "yes". You can either select the code you want to match, if that's your intent, and then call up the Find dialog via a CTRL-F for example, and then do a Find Next, or you could insert the appropriate line breaks in your search text using a ^p, or equivalent. Read the Help on the Find dialog for more details on this and other capabilities.

      Dan
      Daniel Kirkdorffer
      http://www.kirkdorffer.com/

      61
      NewbieNewbie
      61

        Aug 20, 2004#3

        Is there a way to search accross an unknown set of lines? So for instance I have:

        public void test() {
        ...
        ...
        ...
        }

        And I could match from the first { to the closing }. I think other programs use a multi-line mode for this.

        Any thoughts?

        38
        Basic UserBasic User
        38

          Aug 20, 2004#4

          Refer to documentation regarding the use of regular expressions. You should be able to do what you want to do.

          Dan
          Daniel Kirkdorffer
          http://www.kirkdorffer.com/

          61
          NewbieNewbie
          61

            Aug 20, 2004#5

            Yes you are right. I was in fact doing it wrong.

            This appears to work:
            {.*\p*}


            Thanks!!

            5
            NewbieNewbie
            5

              Aug 30, 2004#6

              Hi Guys,

              this doesn't seem to work for me. I want to search across multiple lines, but it is not known how many lines there are. 2 or more parts need to be found before the replace-function shoud match. So I'm looking for something like ...

              find:

              Code: Select all

              KEY1[?^p^b^r^n]++KEY2
              or better, because i have to replace something in KEY2:

              find:

              Code: Select all

              ^(KEY1[?^p^b^r^n]++^)KEY2
              replace:

              Code: Select all

              ^1KEY3
              nothing seems to work as soon as I try to go multiline.Tryed both syntax variants:

              Code: Select all

              KEY1[.\p]*KEY2
              No difference.

              please help.
              Beejai

              206
              MasterMaster
              206

                Aug 30, 2004#7

                Maybe you can get an idea here that will help:

                General thread: How do I replace multiple lines
                Software For Metalworking
                http://closetolerancesoftware.com

                61
                NewbieNewbie
                61

                  Aug 30, 2004#8

                  Yeah my previous solution only worked in one case. It should be simple to select code fragements like this:

                  Code: Select all

                  function blah (
                        int a=1;
                        a++;
                        ......
                  )
                  If I want to select the function body from ( to ) I do not appear to be able to when the number of lines between the brackets is unknow.

                  I tried: (.*\p*) and \(.*\p*\)

                  Is there a solution anyone is aware of? Other Regex solutions appear to be able to handle this via a flag. I really do not thing a macro should be the answer.

                  Thanks!

                  5
                  NewbieNewbie
                  5

                    Aug 30, 2004#9

                    mrainey56 wrote:Maybe you can get an idea here that will help:

                    General thread: How do I replace multiple lines
                    Sorry, but no, that didn't help. I have to do a s&r on a folder structure containing thousands of files.

                    The problem can be tracked down to one thing: Is there a way to specify a unknown number of Lines in UE's regExp-ability ? As soon a working solution for

                    Code: Select all

                    [?^p]++
                    is found, all probs in this thread would be solved.

                    If it can't be done, it should realy be added to the todo-list on UE v10.20d / 10.30

                    please help
                    Beejai

                    2
                    NewbieNewbie
                    2

                      Oct 24, 2004#10

                      Hum, this seems to work for me.

                      I have a multine text :

                      Code: Select all

                      string1
                      any
                      number
                      of
                      lines
                      string2
                      With UE set on unix regexp, doing a 'replace in files' with :

                      Find :

                      Code: Select all

                      (string1)(.*\p*)(string2)
                      Replace with : \1 \3
                      Regexp : on

                      will output :

                      Code: Select all

                      string1
                      string2
                      Thierry B.

                      5
                      NewbieNewbie
                      5

                        Oct 28, 2004#11

                        Hey, above would be ace. But I can't reproduce that.
                        I got 100 testfiles, one contains:

                        Code: Select all

                        <head><meta name="Schluessel" content="PK-V0000-T4444-D0000-N0000-G310805-A0000-X0000-B00000002">
                        
                        <meta http-equiv="Pragma" content="no-cache">
                        <meta http-equiv="expires" content="1800">
                        <meta name="Date" content="01.09.2001">
                        <title>pin8</title>
                        </head>
                        Find: (N0000)(.*\p*)(pin8)
                        Replace: \1 \3
                        RegExps set to unix style
                        Output: Replaced 0 occourences in 0 files.

                        ?? :cry:
                        plz help.
                        Beejai

                        2
                        NewbieNewbie
                        2

                          Nov 04, 2004#12

                          Ok, I understand why. This is because in my case, pattern (string1) and pattern (string2) are the exact content of a full line, not a part of line as in your case.

                          TB

                          Edit: This is a potential bug in UE because I tested your case in Visual Regexp 3.0 and it works (http://laurent.riesterer.free.fr/regexp/). See picture :

                          5
                          NewbieNewbie
                          5

                            Nov 05, 2004#13

                            thierrybo wrote:Ok, I understand why. This is because in my case, pattern (string1) and pattern (string2) are the exact content of a full line, not a part of line as in your case.

                            Edit: This is a potential bug in UE because I tested your case in Visual Regexp 3.0 and it works (http://laurent.riesterer.free.fr/regexp/).
                            I agree. I tried to explicit define the strings as part of a line with

                            Code: Select all

                            (.*string1)(.*\p*)(string2.*) or (.*string1.*)(.*\p*)(.*string2.*)
                            but it didn't work either.
                            Then I realized there must be something wrong with the ".*STRING" pattern in general. Try this:
                            Testfile:

                            Code: Select all

                            <head><meta name="Schluessel">
                            <head><meta name="Schluessel" content="PK-V0000-T4444-D0000-N0000-G310805-A0000-X0000-B00000002">
                            Replace ".*sel" with "****" results in:

                            Code: Select all

                            <head><meta name="Sc****>
                            <head><meta name="Sc**** content="PK-V0000-T4444-D0000-N0000-G310805-A0000-X0000-B00000002">
                            which is terribly wrong !!

                            But a replace ".*Schluessel" with "****" gives the expected result:

                            Code: Select all

                            ****>
                            **** content="PK-V0000-T4444-D0000-N0000-G310805-A0000-X0000-B00000002">
                            It might have something to do with the double quotes. But they should be a normal member of the "."-set.
                            Please can any developer take care of this issue?

                            best regards...
                            Beejai

                            3
                            NewbieNewbie
                            3

                              Jul 11, 2005#14

                              I know this is a dead thread, but I thought I'd post the solution in case anyone else out there is looking.

                              They had an error in their RegExp.

                              (.*\p*) looks for multiple occurrences of any character, followed by multiple occurrences of newline.

                              What you want is (.*\p)* which looks for multiple occurences of (multiple occurences of any character followed by a newline) ie: multiple lines.

                              Cheers

                              Tom | d3
                              http://www.tomauger.com

                              5
                              NewbieNewbie
                              5

                                Jul 11, 2005#15

                                Not as dead as you may think ;)

                                Thanks for the info, but it's still not possible to search across multiple lines with your pattern. If I gave up to quick, can you supply an example ?

                                Beejai

                                Read more posts (4 remaining)