User to user discussion and support for UltraEdit, UEStudio, UltraCompare, and other IDM applications.

Find, replace, find in files, replace in files, regular expressions
10 posts Page 1 of 1
I want to search for ABC using Match whole word in the sample below.
Currently I find the 3 results highlighted in green and orange:
I want to find only the result in green.
That is to say I do not want the hyphen character "-" to be considered a word delimiter.
Is this possible?

ABC
ABCD
ZABC ABCC
ABC-A
ABC-D
Hi,

for example you can use Perl regex:

Code: Select all
(?<![-,])abc(?![-,])

and add another separators to the list [-,] if necessary.

The option Match whole word is still needed, of course.

EDIT: Or if you want to maintain only one separator list: (?<!([-,]))abc(?!\1) ... ignore that expression, it is not working.
Well, Unicode standard defines which character is a word character and this definition can't be customized in UltraEdit for find/replace. Therefore using only Match whole word is not enough to exclude strings containing hyphen/dash character which is a non word character.

fleggy posted already an alternative solution using Perl regular expression with a negative lookbehind and a negative lookahead to additionally check which character before and after the found word is the word delimiter to make the match on ABC negative if it is a hyphen or a comma character.

It is possible to use the Perl regular expression find also without Match whole word option as there is \b (word boundary) and \< (beginning of word) and \> (end of word). Therefore you could for example also use (?<!-)\bABC\b(?!-) or (?<!-)\<ABC\>(?!-) without having checked Match whole word.
Best regards from Austria
To Mofi

For me your regexp and fleggy's (?<![-,])abc(?![-,]) work fine, but (?<!([-,]))abc(?!\1) doesn't work: ABC- is matched ... What I'm missing? (UE 23.10.0.3 x64)
It's impossible to lead us astray for we don't care even to choose the way.
Hi,

the expression (?<!([-,]))abc(?!\1) is wrong, sorry. I didn't test it enough.

Fleggy
Yes, a capturing group within a zero-width lookbehind or lookahead is not possible. The lookbehind / lookahead does not match characters (zero-width) and therefore it is not possible to capture a string for backreferencing.

But backreferencing a string found by a capturing group in a lookbehind or lookahead works. For example the search string ([+,\-])\bABC\b(?!\1) matches the first 4 characters of the first 4 items in the list below, but not the last 3 items at all.

Code: Select all
,ABC
,ABC-
+ABC-
-ABC,
+ABC+
-ABC-
,ABC,
Best regards from Austria
Mofi
fleggy


Thank a lot for clarifications!
It's impossible to lead us astray for we don't care even to choose the way.
Thank you gents.
For some reason did not get notified when posts were made so bit late back here.
I can see much for me to chew over!
Thanks again...
I know this is an oldish thread, but I thought I'd add for clarification that \< and \> are not valid Perlre expressions.

They are supported in the vi editor, but as a contributor to the Perlre forum said: "vi ain't Perl".
There is no single "Perl regular expression". There are multiple regular expression libraries used in multiple applications. The Perl interpreter has embedded a different library than .NET Framework, Qt, JavaScript, vi or UltraEdit. And of course there are different versions of each regex library used in different versions of interpreters and applications.

UltraEdit uses the Boost Regular Expression library in Perl syntax. I don't know which version of the library is used by which version of UltraEdit. And I also don't know what is supported from the Boost regex library in UltraEdit/UEStudio and want can't be used in UltraEdit/UEStudio. This must be find out by trial and error/success.

The "Perl syntax regular expression" library embedded in UltraEdit for Windows interprets \< as beginning of a word and \> as end of a word.

This can be seen in list opened when having Regular expressions option in Find/Replace dialog enabled, having Perl selected, and having clicked on button with .* (or a magnifying glass or with a triangle in older UE versions) above (or right of) Find what edit field. For Perl this list is not complete as such a list would not fit on screen. But it contains the most often used regular expressions which can be inserted in search string at current caret position by clicking on the list item. The list for the replace string is of course different.
Best regards from Austria
10 posts Page 1 of 1