Jump to content

(*SOLVED*) Help with regular expression


bljepp69

Recommended Posts

I've been trying to come up with a single regular expression to break a string apart, but I've not been able to get one that works in all instances.  I have a string of song names.  The way it's given to me is shown in the example text below:

1.20th Century Boy2.Rock On3.Hanging On The Telephone4.Waterloo Sunset5.Hell Raiser6.10538 Overture7.Street Life8.Drive In A Saturday9.Little Bit Of Love10.Golden 21 Of Rock & Roll11.No Matter What12.He's Gonna Step On You Again13.Don't Believe A Word14.Stay With Me

It's easy enough to find all the song numbers.  Something like - '/([\d]{1,2}\.)/' - will return just the song numbers.  When I try to expand the expression to find the song names, the closest I can get is - '/([\d]{1,2}\.[^(\d{1,2}\.)]+)/'.   However, that won't return song names that start with numbers, such as number 1 and 6 above, and it truncates number 10 at the number.

I'm really hoping to be able to split this into the proper pieces with a single reg ex.  Any help is appreciated.
Link to comment
Share on other sites

Try using preg_split() on it to get your song names.
[code]
<?php
// where $String is your list of songs
$names = preg_split('/[\d]{1,2}\./', $String);
?>
[/code]

$names should then hold an array of all the song names. You may have to run a trim() on them to get rid of some leading spaces, but I think this will help you out.

Good luck
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.