RegExp in Macro failing

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

RegExp in Macro failing

Postby alanb » Thu Sep 15, 2005 11:50 am

I have a text file with up to 100000 lines like the following:

$P:U
$A:A
$C:Code_Opportunity
$U:N
$V:' '
$P:U
$A:A
$C:Code_Ratings_Code
$U:N
$V:' '
$T:CHAR(1)

Each "tag" starts with "$" and ends with ":". They should be in groups of 6 lines, one each of: $P: $A: $C: $U: $V: $T: in a group.

However, there may be some "$T:" tags missing (see the first group, above), so I want to parse the file and identify the missing "$T:" tags and insert them as "$T:<missing>".

To make matters worse, I will also have to do the same for missing "$V:" tags...

I tried the (Ultraedit style) Find RegExp "^$V:*^P%^$P:" but this finds every $V: tag. Also "^$V:*^P%^$P:" finds none.

Hope the above is clear, but what am I doing wrong?

TIA
User avatar
alanb
Newbie
 
Posts: 8
Joined: Tue Sep 13, 2005 11:00 pm
Location: Essex, England

Re: RegExp in Macro failing

Postby Mofi » Thu Sep 15, 2005 12:17 pm

Use ^$V:*^p^$P:

% (= start of line) can be only used once in the search string at begin of the search string. By specifying ^p you have already specified also start of next line. To see this, simply search for a single ^p and look where the cursor is now. It is not at the end of the line, it is at start of the next line.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: RegExp in Macro failing

Postby alanb » Thu Sep 15, 2005 12:21 pm

Thanks, Mofi - but this still does not work (copied and pasted from your reply)!

It finds:

$V:' '
$T:CHAR(1)
$P:U

and I need to find:

$V:' '
$P:U
$A:A
User avatar
alanb
Newbie
 
Posts: 8
Joined: Tue Sep 13, 2005 11:00 pm
Location: Essex, England

Re: RegExp in Macro failing

Postby Mofi » Fri Sep 16, 2005 5:37 am

You have found a bug within UltraEdit's regular expression. UltraEdit is selecting everything after second ^$ until a P: is found. If using ^$V:*^p^$*T: it finds

$V:' '
$P:U
$A:A
$C:Code_Ratings_Code
$U:N
$V:' '
$T:

and this is definitively not OK.

I found a workaround for this bug - use ^$V:*^p^$*P:
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: RegExp in Macro failing

Postby alanb » Fri Sep 16, 2005 6:32 am

Thanks again Mofi - I guessed it had to be a bug & I'm mailing Ian and the Uedit team about it now.

Your workaround works fine!
But can you explain (why you think) it works, please?

Regards
Alan
User avatar
alanb
Newbie
 
Posts: 8
Joined: Tue Sep 13, 2005 11:00 pm
Location: Essex, England

Re: RegExp in Macro failing

Postby Mofi » Fri Sep 16, 2005 7:19 am

I have already sent an email about this problem to IDM support with a link to this forum topic and extra description.

I inserted the * after second ^$ because * means any numbers of characters which includes also number 0. I also don't know, why UltraEdit searches for P: after second $ and ignoring all characters between the $ and P:. We have to wait for the answer of the IDM developers.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: RegExp in Macro failing

Postby alanb » Fri Sep 16, 2005 7:58 am

OK Mofi.

The good news is that I am now able to replace 4 loops in my original macro with 4 RegEX Find/Replace which works many times faster.

I have another query with the macro which I'll post in the appropriate forum if I can't find an answer in previous posts.

Thanks again for your time,
Alan
User avatar
alanb
Newbie
 
Posts: 8
Joined: Tue Sep 13, 2005 11:00 pm
Location: Essex, England


Return to Find/Replace/Regular Expressions