Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: benny! on July 23, 2008
-
Hi,
anyone good at regular expression. I try to transform the
following example list :
http://www.google.de/eins/index.html
http://code.google.de/zwei/test.html
http://eins.zwei.google.de/
into something like this:
google.de
google.de
google.de
using java ?
Anyone a regex-guru ?
-
I'd be tempted to do something like
var dots=url.split('.');
var len=dots.length;
var base_url=dots[len-2]+'.'+dots[len-1].split('/')[0];
Jim
-
\w*\.\w*(?=/)
\w* match multiple character (a-z, A-Z, 0-9, or _)
\. match a fullstop
\w* match multiple character (a-z, A-Z, 0-9, or _) again
(?=/) means don't include in the results, but look ahead for a /
This works on the examples you listed.
-
@Voltage:
Thanks - I will try that.
@Jim:
Thanks - but I hoped to save some perfomance with regular
expression. But if that doesnt work - I'll try your idea.