• Welcome to Dark Bit Factory & Gravity.
 

Regular expressions

Started by benny!, July 23, 2008

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

benny!

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 ?
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Jim

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
Challenge Trophies Won:

Voltage



\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. 
Challenge Trophies Won:

benny!

@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.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: