Author Topic: Regular expressions  (Read 2370 times)

0 Members and 1 Guest are viewing this topic.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Regular expressions
« 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 ?
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Regular expressions
« Reply #1 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
Challenge Trophies Won:

Offline Voltage

  • Professor
  • Pentium
  • *****
  • Posts: 857
  • Karma: 53
    • View Profile
Re: Regular expressions
« Reply #2 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. 
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Regular expressions
« Reply #3 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.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: