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
https://forums.phpfreaks.com/topic/25705-solved-help-with-regular-expression/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.