How to choose optional characters? (?) doesn't work.

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

How to choose optional characters? (?) doesn't work.

Postby psmithphil » Thu Mar 17, 2005 6:29 pm

I have a test text file which contains these 3 lines:
color colour
color
colour

When I use "Find", I use Unix Regular Expressions. I have the latest UltraEdit (ver 11).
I want to use "Find" to search for the word "color" and optionally "colour". So I put "colou?r" in the search box and the search finds nothing. If I go outside of UltraEdit and use egrep in a DOS box (egrep -i colou?r <filename>) then it works fine and finds both words.
Apparently the ? metacharacter does not work in UltraEdit. How would I perform such an optional search in UltraEdit? Thank you!
User avatar
psmithphil
Newbie
 
Posts: 5
Joined: Wed Mar 16, 2005 12:00 am
Location: Kansas, USA

Re: How to choose optional characters? (?) doesn't work.

Postby mrainey56 » Thu Mar 17, 2005 6:35 pm

Maybe colo[u]*r
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How to choose optional characters? (?) doesn't work.

Postby psmithphil » Thu Mar 17, 2005 9:36 pm

Mrainey, you are amazing! What you suggested worked great. I guess what your code says is "none or more of the preceding character".
I've read Freidl's book on Regular Expressions and have picked it up again since discovering I can use Unix RegEx's in UltraEdit. It's cool to see them work as you go through the text file.
And I'm happy that you have shown me how to use something I'll use a lot. Thank you!
User avatar
psmithphil
Newbie
 
Posts: 5
Joined: Wed Mar 16, 2005 12:00 am
Location: Kansas, USA

Re: How to choose optional characters? (?) doesn't work.

Postby psmithphil » Fri Mar 18, 2005 11:57 am

One thing I did notice about using "colo[u]*r" is that it will also pick up "colouuuuuur". It doesn't appear to be an issue now and I hope I will see how to get around it as I review Friedl's book. It appears UltraEdit needs to add the "?" feature to it's Unix Regular Expressions, but I'm not educated enough on the subject to say for sure.
User avatar
psmithphil
Newbie
 
Posts: 5
Joined: Wed Mar 16, 2005 12:00 am
Location: Kansas, USA

Re: How to choose optional characters? (?) doesn't work.

Postby mrainey56 » Fri Mar 18, 2005 12:28 pm

You'll find that the UE implementation of regular expressions is missing a number of capabilities you'll read about in your book.

Most of the time you can figure out a way to make the UE regex do what you want.
User avatar
mrainey56
Master
Master
 
Posts: 212
Joined: Tue Jul 27, 2004 11:00 pm
Location: Spartanburg, South Carolina

Re: How to choose optional characters? (?) doesn't work.

Postby psmithphil » Fri Mar 18, 2005 2:10 pm

Yes, I think you are right, that I will most of the time find what I need with UltraEdit's RegEx. I'm going to keep using it for much of my file search and replace and other repair. I need to find something that I can use when I need to do heavyweight RegEx stuff, but I have not found a tool yet that works consistently.

I want to thank you again for your outstanding help!
User avatar
psmithphil
Newbie
 
Posts: 5
Joined: Wed Mar 16, 2005 12:00 am
Location: Kansas, USA


Return to Find/Replace/Regular Expressions