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");
...

Nessun commento: