Searching across multiple lines

Find, replace, find in files, replace in files, regular expressions

Searching across multiple lines

Postby JoeBelmaati » Tue Aug 17, 2004 12:16 pm

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
User avatar
JoeBelmaati
Newbie
 
Posts: 2
Joined: Mon Aug 16, 2004 11:00 pm

Re: Searching across multiple lines

Postby DanKirkd » Wed Aug 18, 2004 1:43 pm

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
User avatar
DanKirkd
Basic User
Basic User
 
Posts: 39
Joined: Wed Jul 14, 2004 11:00 pm

Re: Searching across multiple lines

Postby ahbrown41 » Fri Aug 20, 2004 10:29 am

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?
User avatar
ahbrown41
Newbie
 
Posts: 6
Joined: Thu Aug 19, 2004 11:00 pm

Re: Searching across multiple lines

Postby DanKirkd » Fri Aug 20, 2004 11:38 am

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

Dan
User avatar
DanKirkd
Basic User
Basic User
 
Posts: 39
Joined: Wed Jul 14, 2004 11:00 pm

Re: Searching across multiple lines

Postby ahbrown41 » Fri Aug 20, 2004 12:01 pm

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

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


Thanks!!
User avatar
ahbrown41
Newbie
 
Posts: 6
Joined: Thu Aug 19, 2004 11:00 pm

Re: Searching across multiple lines

Postby beejai » Mon Aug 30, 2004 7:24 am

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
User avatar
beejai
Newbie
 
Posts: 5
Joined: Sun Aug 29, 2004 11:00 pm

Re: Searching across multiple lines

Postby mrainey56 » Mon Aug 30, 2004 8:03 am

Maybe you can get an idea here that will help:

General thread: How do I replace multiple lines
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: Searching across multiple lines

Postby ahbrown41 » Mon Aug 30, 2004 9:23 am

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!
User avatar
ahbrown41
Newbie
 
Posts: 6
Joined: Thu Aug 19, 2004 11:00 pm

Re: Searching across multiple lines

Postby beejai » Mon Aug 30, 2004 10:19 am

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
User avatar
beejai
Newbie
 
Posts: 5
Joined: Sun Aug 29, 2004 11:00 pm

Re: Searching across multiple lines

Postby thierrybo » Sun Oct 24, 2004 9:11 am

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.
User avatar
thierrybo
Newbie
 
Posts: 2
Joined: Sat Oct 23, 2004 11:00 pm

Re: Searching across multiple lines

Postby beejai » Thu Oct 28, 2004 8:32 am

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
User avatar
beejai
Newbie
 
Posts: 5
Joined: Sun Aug 29, 2004 11:00 pm

Re: Searching across multiple lines

Postby thierrybo » Thu Nov 04, 2004 12:49 pm

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 :
Image
User avatar
thierrybo
Newbie
 
Posts: 2
Joined: Sat Oct 23, 2004 11:00 pm

Re: Searching across multiple lines

Postby beejai » Fri Nov 05, 2004 4:39 am

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
User avatar
beejai
Newbie
 
Posts: 5
Joined: Sun Aug 29, 2004 11:00 pm

Re: Searching across multiple lines

Postby grymmjack » Mon Jul 11, 2005 9:57 am

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
User avatar
grymmjack
Newbie
 
Posts: 3
Joined: Sun Oct 09, 2005 11:00 pm

Re: Searching across multiple lines

Postby beejai » Mon Jul 11, 2005 10:56 am

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
User avatar
beejai
Newbie
 
Posts: 5
Joined: Sun Aug 29, 2004 11:00 pm

Next

Return to Find/Replace/Regular Expressions