★ Regular expressions
posted Sun 11 Jun 2006 by Michael Galloy under IDLI wrote āMaking Regular Expressions Your Friendsā while I was at RSI (and while it was still RSI). Regular expressions are a ālittle languageā embedded inside IDL (and most other modern languages) with very powerful string processing capabilities. In the whitepaper, all the details of IDLās implementation of regular expressions are explained with examples (including the undocumented stuff). Also included in the download is the STR_REPLACE
routine (download).
STR_REPLACE
can do search and replace actions on strings. For example,
IDL> print, str_replace('data001.dat', 'data', 'precip')
precip001.dat
replacing ādataā with āprecipā in ādata001.datā. The cool part about it is you can replace one regular expression with another, even evaluating IDL expressions in the process. For example,
IDL> search = '([[:alpha:]]+)([0-9]+)'
IDL> replace = 'strupcase(''$1'') + string(fix($2), format=''(Z0)'')'
IDL> print, str_replace('precip032.dat', search, replace, /evaluate)
PRECIP20.dat
Read the whitepaper whitepaper if thatās a bit too dense to follow.
UPDATE 1/22/14: Updated links.
UPDATE 1/23/14: I recommend using MG_STREPLACE
instead of the STR_REPLACE
shown above.
October 26th, 2006 at 11:34 pm
Here is a Korean translation of “Making Regular Expressions Your Friends.”
August 25th, 2008 at 3:49 pm
The link to the whitepaper and download now result in a message telling me they are no longer available. Is there another location I can go to for these?
Thanks!
Edward A. Celarier
August 25th, 2008 at 4:05 pm
ITT VIS changed their website around today, the paper seems to be located here.
January 15th, 2010 at 3:21 pm
[…] Regular expressions […]