• Welcome to DNForum.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
    If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the oldest global domain name community on the internet and continues to grow every day. There are over 45,000 domainers on DNForum doing everything from buying domains, selling domains, using our free in-house built tools, learning about domains and discussing domains. Take a minute and Register.

Wanted: Service Anyone good with Regular Expressions?

Status
Not open for further replies.

Mr.Domains

DNF Addict
The Originals
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
 
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);
 
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
 
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.
Back
Top Bottom