Find "Not Beginning With"?

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

Find "Not Beginning With"?

Postby johnmsch » Fri Sep 22, 2006 3:15 pm

I have a file in plain text format that contains paths, one per line, such as:
c:\asdf
c:\asdf\qwerty
c:\Windows
etc...

I'm trying to find a way to search this file for any line that does NOT start with "c:\"

Any ideas?

Thanks
User avatar
johnmsch
Newbie
 
Posts: 3
Joined: Thu Sep 21, 2006 11:00 pm

Re: Find "Not Beginning With"?

Postby Mofi » Sat Sep 23, 2006 10:58 am

Similar to Delete all lines not starting with a special phrase with the only difference that you don't want to delete those lines.

As already written in the thread linked above and several times in other threads a search for NOT("Beginning/Starting With") is in general not possible.

But in your special situation it is possible with following Perl regular expression: ^([^c]|c[^:]|c:[^\\]).*$

Note: This regex works only with the Perl compatible regular expression engine. The legacy Unix and the UltraEdit engine can only have 2 arguments in an OR expression, but here 3 arguments are necessary.

Code: Select all
^ ......... start of a line
(x|y|z) ... OR expression with 3 arguments
[^c] ...... first OR argument matches all lines not starting with character 'c'.
c[^:] ..... second OR argument matches all lines starting with character 'c'
            but second character is not a ':'.
c:[^\\] ... third OR argument matches all lines starting with "c:"
            but third character is not a '\'.
.*$ ....... matches the rest of the line without the line termination
            characters (CRLF for DOS).
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find "Not Beginning With"?

Postby johnmsch » Sat Sep 30, 2006 12:01 pm

Mofi,

Thanks for the reply, but this does not seem to work in UltraEdit 12. Evidently, I wasn't specific enough in my question. I was looking for a way to do this search (for lines not starting with c:\ within UltraEdit. I bring the file up in the editor, then use the Find function.

Thanks again,
John
User avatar
johnmsch
Newbie
 
Posts: 3
Joined: Thu Sep 21, 2006 11:00 pm

Re: Find "Not Beginning With"?

Postby Mofi » Sun Oct 01, 2006 8:12 am

The regular expression I posted works with UltraEdit v12.10b and only with v12.00 and above because the Perl compatible regular expression must be used. I think, you have not specified this regular expression engine at Advanced - Configuration - Search - Regular Expression Engine. That's the reason why it does not work.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find "Not Beginning With"?

Postby johnmsch » Mon Oct 02, 2006 5:43 pm

Mofi,

I had already set the configuration option. The problem was that I was not checking the "Regular Expressions" box in the find dialog. I did that, and the search worked perfectly.

Thanks again!!!!!!!!!!!!!!!!
User avatar
johnmsch
Newbie
 
Posts: 3
Joined: Thu Sep 21, 2006 11:00 pm


Return to Find/Replace/Regular Expressions