Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: benny! on July 23, 2008

Title: Regular expressions
Post 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 ?
Title: Re: Regular expressions
Post by: Jim on July 23, 2008
I'd be tempted to do something like
Code: [Select]
var dots=url.split('.');
var len=dots.length;
var base_url=dots[len-2]+'.'+dots[len-1].split('/')[0];
Jim
Title: Re: Regular expressions
Post by: Voltage on July 24, 2008
Code: [Select]

\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. 
Title: Re: Regular expressions
Post by: benny! on July 24, 2008
@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.