Hi all
I've written a short ruby script for the purposes of checking regular expressions within TextMate.
http://dml.homedns.org/rx_helper.rb
It expects to be fed a regular expression on a line of its own, followed by any number of lines to test against. The RX can be either a straight match (eg ^([a-z]+):([0-9]+ ) or a substitution (eg, /old/new/). Cuddling /slashes/ are only required for /pattern/replacement/ expressions.
If you create the following action in TextMate:
echo "$TM_SELECTED_TEXT" | /path_to_script/rx_helper.rb
with input='selected text' & output='show as tooltip', you can open a new window, write a regexp, write some test cases for your regexp, then select-all and see the results in a tooltip whenever you need it (I have it bound to ctrl-alt-option-X).
I hope someone finds it useful. If you find any bugs / have any suggestions on how to improve it, please do let me know.
cheers
D
P.S here's some sample input and output: ------------------------------------ IN (TextMate scratch file) == (http|https|ftp)://(([-_a-zA-Z1-9]+).)+([-_a-zA-Z1-9]{2,3}) http://www.google.com https://www.netbank.com.au ftp://mafia.ru www.clickstart.com boozehound gary sweeney http://www.amazon.com/ http://www.amazon.com/exec/obidos/subst/home/home.html/002-0270779 -6984007 ~
OUT (tooltip) == (http|https|ftp)://(([-_a-zA-Z1-9]+).)+([-_a-zA-Z1-9]{2,3}) Successful Matches: =================== http://www.google.com : matched expression match number [1] : http match number [2] : google. match number [3] : google match number [4] : com https://www.netbank.com.au : matched expression match number [1] : https match number [2] : com. match number [3] : com match number [4] : au ftp://mafia.ru : matched expression match number [1] : ftp match number [2] : mafia. match number [3] : mafia match number [4] : ru http://www.amazon.com/ : matched expression match number [1] : http match number [2] : amazon. match number [3] : amazon match number [4] : com http://www.amazon.com/exec/obidos/subst/home/home.html/002-0270779 -6984007 : matched expression match number [1] : http match number [2] : amazon. match number [3] : amazon match number [4] : com
Failed Matches: =============== www.clickstart.com : failed boozehound : failed gary sweeney : failed