Inverse searching Regular Expression problem

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

Inverse searching Regular Expression problem

Postby ktfung » Wed Aug 08, 2007 9:57 am

Hi,
I have a problem in Regular Expression.

File 1 is:
ABCgg003D

if I want to search with any text start with BC and the end is 003 in File 1. I use BC*003 in find function. That work fine. Found 1 result.

File 2 is:
ABCgg002D

if i want text start with BC but not end with 003 in File 2. I have try BC*~^{003^}. I suppose 1 will be found. But the result is 0.

What Regular Expression should i use?
THX:)
User avatar
ktfung
Newbie
 
Posts: 2
Joined: Tue Aug 07, 2007 11:00 pm

Re: Inverse searching Regular Expression problem

Postby Mofi » Wed Aug 08, 2007 11:04 am

First read the sticky forum topic in this forum. Then tell us your version of UE/UES and which regex engine you use.

Usually it is not possible to search "if a string is not at ...". With the UltraEdit and the Unix engine it is definitely not possible what you want. Only possible is "next character is not a or b or c or ..." by using [~abc] in UltraEdit syntax or [^abc] in Unix syntax.

If BC*~^{003^} should be an UltraEdit regex search string, than this is a completely invalid one and so does never find something.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Inverse searching Regular Expression problem

Postby pietzcker » Wed Aug 08, 2007 12:04 pm

If you have an UE version >12, you can use the Perl regex engine that features negative lookahead.

Code: Select all
BC(?:(?!003).)*$

will find "BC" followed by anything except 003 until the end of line.

I.e., ABCgg003D won't match, ABCgg002d will match BCgg002d.

HTH,
Tim
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Inverse searching Regular Expression problem

Postby ktfung » Thu Aug 09, 2007 1:55 am

Thanks for replies!

My UltraEdit version is 13.10a+1.

I have tried
Code: Select all
BC(?:(?!003).)*$
, but the result still is 0 in File 2 (BCgg002d). Should I configure something before use Perl regex engine?
User avatar
ktfung
Newbie
 
Posts: 2
Joined: Tue Aug 07, 2007 11:00 pm

Re: Inverse searching Regular Expression problem

Postby pietzcker » Thu Aug 09, 2007 5:44 am

Did you read the sticky, esp. section 2?

And of course, did you check "Regular Expressions" in the Find dialog?
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm


Return to Find/Replace/Regular Expressions