bljepp69 Posted October 31, 2006 Share Posted October 31, 2006 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 More sharing options...
Psycho Posted October 31, 2006 Share Posted October 31, 2006 There is a dedicated forum here specifically for regular expressions: http://www.phpfreaks.com/forums/index.php/board,43.0.html Link to comment https://forums.phpfreaks.com/topic/25705-solved-help-with-regular-expression/#findComment-117296 Share on other sites More sharing options...
obsidian Posted October 31, 2006 Share Posted October 31, 2006 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 https://forums.phpfreaks.com/topic/25705-solved-help-with-regular-expression/#findComment-117300 Share on other sites More sharing options...
bljepp69 Posted October 31, 2006 Author Share Posted October 31, 2006 Thanks! That's the help I needed to finish this up. Link to comment https://forums.phpfreaks.com/topic/25705-solved-help-with-regular-expression/#findComment-117304 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.