views:

58

answers:

2

Hi,

I have the following Regexp to create a hash of values by separating a string at a semicolon:

Hash["photo:chase jarvis".scan(/(.*)\:(.*)/)] 
// {'photo' => 'chase jarvis'}

But I also want to be able to have URL's in the string and recognize it so it maintains the URL part in the value side of the hash i.e:

Hash["photo:http://www.chasejarvis.com".scan(/(.*)\:(.*)/)] 
// Results in {'photo:http' => '//www.chasejarvis.com'}

I want, of course:

Hash["photo:chase jarvis".scan(/ ... /)] 
// {'photo' => 'http://www.chasejarvis.com'}

Appreciate your help!

A: 

How do figure out a person's family name and first name?

Changing chasejarvis to chase and jarvis might not be possible unless you have a solution for that.

Do you already know everyone's name in your project? Nobody is having the initial of a middle name like charvisdjarvis (assuming the name is "Charvis D. Jarvis".)?

TK
+1  A: 

If you only want to match up to first colon you could change (.*)\:(.*) to ([^:]*)\:(.*).

Alternatively, you could make it a non-greedy match, but I prefer saying "not colon".

Dave Webb