Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

UltraEdit regular expressions

Every now and then I find myself needing to use a regular expression in UltraEdit, and whenever I do I invariably have to spend five minutes re-reading that section of the manual to remind myself how its syntax differs from more traditional regular expressions. This time, I’m recording the result in the hope that it might jog my memory next time I need to use them.

The task completed by this regular expression is to turn a file containing numbers like this:

1st
2nd
3rd
...

In to this:

<option value="1">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>

Find: %^([0-9]+^)^(?+^)$ and Replace with: <option value="^1">^1^2</option>

This is UltraEdit regular expressions by Simon Willison, posted on 23rd March 2003.

View blog reactions

Next: Smart scripted URLs

Previous: PHP5 info from Sterling Hughes

5 comments

  1. You do know that you can use Unix style REs in UE, don't you? Just check the Advanced | Configuration | Find | Unix style Regular Expressions checkbox and it works more-or-less as usual.

    Shot - 23rd March 2003 17:24 - #

  2. Search for: var $username; Replace with: $this->username = null; Search for: var[ ^t^b]^$^(?+^); Replace with: $this->^1 = null;

    raz0 - 10th January 2004 19:41 - #

  3. 1 year after the post I stumbled on this. Thanks for the tip, I didn't realize you could set Ultraedit to use unix regex.

    Jeff Bailey - 13th February 2004 06:22 - #

  4. You can, but not for the function list expression (populates the function list panel) defined in wordfile.txt. This has to be in ultraedit format, which doesn't appear to allow character groups to be defined. I'm trying to match "%^t++([pP]ublic )++[fF]unction*$" but the round brackets seem to result in zero matches. Curly brackets don't work either and the Help doesn't suggest an alternative as far as I can see. Bah!

    Jon Kemp - 23rd November 2004 15:16 - #

  5. Oh dear, I hope you delete these posts to tidy up your forum... I was puzzling over the cryptic help again when I realised that you have to ^escape the curly brackets! Hence the strange "^{John^}^{Tom^}" expression to match "John" or "Tom". I'd always wondered what those extra ^ were doing in there! I just switched to Unix style expressions though, so never had the need to work it out till now. My expression is now more like "%^t++^{[pP]ublic ^}++[fF]unction*$" although needs some more fiddling.

    Jon Kemp - 23rd November 2004 15:36 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2003/03/23/ultraEditRegularExpressions

A django site