Regular Expressions in Java

Need to use regular expressions (regex) for common tasks in Java?
Here is a quick example:

import java.util.regex.Pattern
import java.util.regex.Matcher
 
// ...
 
Pattern pattern = Pattern.compile("pattern");
Matcher matcher = pattern.matcher("subject");
 
// find (sub)matches
while(matcher.find()) {
    String nth_match = matcher.group();
}
 
// veryfy that the whole subject matches the pattern
Boolean does_it_matches = matcher.matches()
 
// replace all the occurrence of a regex in a String (no import needed)
"string instance".replaceAll("regex","replacement");

For other tasks take a look at the Matcher class javadoc.


Innovation Lab 2010

Innovation Lab 2010, Young Go-Getter Team

Does this look like a successful team ?
I spent the last days ( or weeks ? ) working with these guys at the business idea we submitted for this great chance. Even if we started with another completely different idea that we discarded in the middle of the timeline, the current idea has been in my mind for a couple of years, and my hope was to put it into a concrete form. We really worked hard on it, think about that: we spent last sunday and yesterday night till midnight at a MacDonald because in that period of time it was the only place with an internet connection we can stay and work :P

Anyway, the Innovation Lab 2010, that yesterday hitted wired news (it) is close to its grand final: tomorrow is the big day! Everyone interested is welcome from 9:30 for the Green Brand and from 14:30 for the Innovation Lab speeches and presentations. The place is the Business College “Federico Caffè” in Rome ( here ). Will follow the upstart drink by Upstart Roma.


Web app backup simple shell script

Backup Recently, the unofficial discussion board for students of my university department went down because of a misunderstanding with their hosting provider who also reassigned their machine to another customer wiping out all of their data. Now they restore the board but the last backup was dated back to last year so lots of data have been lost. Anyway, when one of the admins announced on facebook the board was up again, i ironically commented writing a small shell script that can be used to backup a simple mysql-based web application such as a discussion board or a CMS installation such as drupal, joomla, wp or whatever… But then i thought this happend more frequently than expected to people i know, so i decided to post that script here :)

#!/bin/bash
#-----------------------------------
# Web App. Dumb Backup Script
# http://www.n0on3.net
#-----------------------------------
$user='your-username-here'
$server='your-domain-name-here'
$appname='your-webapp-name-here'
$apppath='your-webapp-path-here'
$mysqluser='your-mysql-user-here'
$mysqlpassword='your-mysql-pwd-here'
$dbname='your-mysql-db-name-here'
#-----------------------------------
d=`date +'%d-%m-%y'`
ssh $user@$server "tar cjvf backup-$appname-$d-www.tar.bz2 $apppath"
ssh $user@$server "mysqldump -u $mysqluser
                  --password=$mysqlpassword $dbname
                  > backup-$appname-$d-db.sql"
scp $user@$server:$HOME/$user/backup-$appname-$d-www.tar.bz2 \
                  backup-$appname-$d-www.tar.bz2
scp $user@$server:$HOME/$user/backup-$appname-$d-db.sql \
                  backup-$appname-$d-db.sql
ssh $user@$server 'rm backup-$appname-$d-*'

Please notice that here you are using ssh login without password, that means you have to append your client machine public rsa id to your server authorized keys file.
But more important, here you are writing your database password in plaintext because the script must use it, so if you keep such a script on your client machine remember to encrypt it or to take any proper precaution ;)


Huge numbers




I’m preparing sheets for the Business Plan i’m going to present with a group of colleagues at the Innovation Lab that Roma Tre University organized. Huge numbers i’m coming to, made me remember this video. Every time i see that, just perceiving the growing of complexity we are living, i feel shivers. Don’t you ?


EH Miracle on Thirty-Hack Street A&W out

EH-MTHSAnswers and Winners for Ethical Hacker Network Christmas Contest Miracle on Thirty-Hack Street are out. Unfortunately my answer was not enough complete :D . Anyway, this is a nice chance to spread something on the most famous socnet users privacy management.

This is the answer i submitted on Jan 6 2010:

Read more


Google Maps Street View goes 3D

Do you own a pair of anaglyph glasses ? You probably know them because of the 3D-movies at the cinema, they’re pretty in fashion right now. Well, if you are that lucky, you can now enjoy Google Maps Street View in 3D! I don’t have the glasses, and i don’t know if it’s a late-to-go april fool, but … c’mon that’s amazing, isn’t it ? I think i’m going to see a 3D movie in some cinema where you can keep the glasses after the 3D projection just to try how this feels :P



Return top

About me