Visualizzazione post con etichetta regexp. Mostra tutti i post
Visualizzazione post con etichetta regexp. Mostra tutti i post

martedì 28 gennaio 2014

Learning regex [ENG]

This is wonderful for beginners.

And as a bonus I throw in a regexp replacement pattern for Notepad++ to convert a list of mime types and file extensions in a Java map loading snippet:

Find: ([^\s]*)(\s+)(.*)
Replace: mimemap.put(".\3", "\1");
transforms this:
application/envoy evy
application/fractals fif
application/futuresplash spl
application/hta hta
application/internet-property-stream acx
application/mac-binhex40 hqx
application/msword doc
application/msword dot
application/octet-stream *
application/octet-stream bin
...
into this:
mimemap.put(".evy", "application/envoy");
mimemap.put(".fif", "application/fractals");
mimemap.put(".spl", "application/futuresplash");
mimemap.put(".hta", "application/hta");
mimemap.put(".acx", "application/internet-property-stream");
mimemap.put(".hqx", "application/mac-binhex40");
mimemap.put(".doc", "application/msword");
mimemap.put(".dot", "application/msword");
mimemap.put(".*", "application/octet-stream");
mimemap.put(".bin", "application/octet-stream");
...

giovedì 16 gennaio 2014

Eclipse Regex to match simple getter/setter methods

To match simple getters/setters:
public .* [g|s]et(.)*(\r\n)(.)*\{(\r\n).*(\r\n).*\}

lunedì 12 luglio 2010

Fun with RegExp [ENG]

Today it is another of those Regular Expressions Appreciation Days I sometimes like to hold. RegExp are not beautiful nor elegant, but they are very powerful.
Let's say you have a batch file which begins setting some variables:
set REGASM_HOME=c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
set V_HOME=c:\programmi\v
set V_HOME=c:\programmi\v
set DWVF_DLL=D.V.dll
set TEMPDIR=c:\dev\_deploy
set VFAP_DLL=VPOD.dll
If you need to echo the stuff for debugging purposes (and don't want to use a SET command) you must add as many lines like this:
echo REGASM_HOME=%REGASM_HOME%
Putting that all in by hand, even with smart cut & paste, would require time and is prone to errors (and it is so not cool, is it now?). What about a good editor and some regular expressions? I copied the above lines and applied these search & replace patterns:
search for: set (\w*)(=)(.*)$
replace with: echo $1=%$1%
et voilà, les jeux sont fait!
If you want to toy with regular expressions try Regex Coach: it is a very useful tool.