I want to replace all words in a wordlist that have one, two or three letters.
I tried (^...\r|^..\r|^.\r) in UNIX style, but it only works if I combinate two and not three terms.
Multiple OR combinations are not possible yet in UltraEdit with the UltraEdit or the Unix regular expression engine. Use a macro with a sequence of two or more replaces.
Edited on 2008-10-29: Since UE v12.00 it is possible by using the Perl compatible regular expression engine, see below.
Best regards from an UC/UE/UES for Windows user from Austria
If you are using a more recent version which supports Perl regex, i.e. Version 12 or later, you can set it for Perl regular expressions and solve this a few ways.
If you are looking for simple words of 1 to 3 characters, and the words are separated by non-word boundaries you could do it with the regular expression:
Search for: \b\w{1,3}\b
Replace with nothing
\w will match both letters and numbers. If including numbers is a problem
use:
Search for: \b[A-Za-z]{1,3}\b
If you were actually needing to select from 3 specific words using OR, you could use the Perl regex construct such as:
Can someone help me with a multiple AND combination?
For example, I don't want to search for either "cat" or "dog" I want to search for them both in the same line. I apologize if I am in the wrong section, but this is the first time I have used the forum.
AND is the default, but the order of the words must match the order of occurence in the file. Unix/Perl regular expression search string cat.*dog finds cat AND dog in this order with 0 or more occurences of any other character between except the new line characters. The UltraEdit regular expression search string for this search is cat*dog.
If you don't know the order of the words in the lines, you need to run either muliple searches with all possible combinations like for this example dog.*cat or use an enhanced Perl expression as posted below by pietzcker which really works independent of the order which finds lines where both words exist on the same line in any order.
Best regards from an UC/UE/UES for Windows user from Austria
If you want to match an entire line if and only if it contains both "cat" and "dog", use the following Perl regex:
^(?=.*\bcat\b)(?=.*\bdog\b).*\r\n
Explanation:
^ anchors the regex at the start of the line (?=.*\bcat\b) asserts that it is possible to match any number of characters, followed by the word "cat" (the \b word boundary anchors ensure that it doesn't match "complicate" oder "catastrophe"). This is called "positive lookahead". (?=.*\bdog\b) same for the word "dog". If you have more search terms, just add them the same way. .*\r\n matches the entire line including linebreaks.
Unfortunately, the last line means that the regex will fail if "dog" and "cat" occur on the last line of the file unless that's also CRLF terminated. Correctly, I would have used \r?\n? instead of \r\n to make those linebreaks optional. However, due to a bug in UE's regex engine, this doesn't work (it skips matches in adjacent lines). So either use \r?\n? and apply the regex multiple times in a row, or make sure that the last line of the file is CRLF terminated.