Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
Sedo.com

Wanted: Service Anyone good with Regular Expressions?

Status
Not open for further replies.

Mr.Domains

DNF Addict
Legacy Exclusive Member
Joined
Sep 29, 2004
Messages
1,417
Reaction score
29
Anyone good with Regular Expressions, that can spare me 30 seconds of their time? Basically, I have bible reference strings that look like this:

Matthew 7:7-8
Proverbs 23:7
Ephesians 5:25
etc...

I want to split them into Book, and Reference, like:
$book="Matthew", $ref="7:7-8"
$book="Proverbs", $ref="23:7"
$book="Ephesians", $ref="5:25"

The closest I've got is:
$ref = ereg_replace("(.*)([0-9]*:[0-9]*)","\\2",$string);
$book = str_replace("$ref","",$string);

But for some reason, this seems to return:
$book="Matthew 7", $ref=":7-8"

... what am I doing wrong!?!
Thanks,

Neil
 

Spinlock

Level 3
Legacy Platinum Member
Joined
May 17, 2006
Messages
52
Reaction score
0
You might try the following:
Code:
$ref = ereg_replace("(.*[[:space:]])([0-9]*:[0-9]*)","\\2",$string);
That should fix your problem. You can clean the space off the book by replacing
Code:
$book = str_replace("$ref","",$string);
with
Code:
$book = str_replace("[[:space:]]$ref","",$string);
 

Brujah

DNF Member
Legacy Exclusive Member
Joined
Jun 10, 2002
Messages
538
Reaction score
0
you might want preg_match
www.php.net/preg_match

Matthew 7:7-8
something like this maybe..
preg_match( '/(\w+) (\d{1,2}:\d{1,2}?\-\d{1,2})/', $input, $match )
$match[1] = book
$match[2] = chapter reference

I didn't test it but I'm thinking something like that. Someone will clean it up
 

Mr.Domains

DNF Addict
Legacy Exclusive Member
Joined
Sep 29, 2004
Messages
1,417
Reaction score
29
Thanks Spinlock, your fix worked fine! And Brujah, I didn't get to try yours, but thanks anyway, I appresiate you efforts! Cheers, guys.
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members Online

Sedo - it.com Premiums

IT.com

Premium Members

MariaBuy

Our Mods' Businesses

UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom