Ortix Posted April 6, 2011 Share Posted April 6, 2011 Sorry for such a bad title, i'm not sure how i can describe this problem So here's the thing: I have this string: [sHiN-Remux][MSPN-SUBS] Ore-tachi ni Tsubasa wa Nai - 01 [1280x720 h.264 AAC][FB36073E].mkv I want it to look like this: Ore-tachi ni Tsubasa wa Nai 01 Currently it looks like this: Ore 01 The reason is that I am using regular expressions and other functions to filter out the stuff i don't need. Most of my strings come in this form: Titleoftheshow - 01 Which is totally fine since this does work. Rarely do they appear like this: title-of-theshow - 01 or even this (which makes things more complicated) title - of - the - show - 01 Now the problem is that after the FIRST dash, everything is deleted. How could i escape all the dashes in that are in between letters and only remove the dash that's between a letter and a NUMBER. Daunting task eh? I have tried several things but i just can't come up with a solution. Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/ Share on other sites More sharing options...
JAY6390 Posted April 6, 2011 Share Posted April 6, 2011 $subject = '[sHiN-Remux][MSPN-SUBS] Ore-tachi ni Tsubasa wa Nai - 01 [1280x720 h.264 AAC][FB36073E].mkv'; $result = trim(preg_replace('/(\[[^\]]+\]|\.mkv)/i', '', $subject)); echo $result; Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/#findComment-1197675 Share on other sites More sharing options...
Ortix Posted April 6, 2011 Author Share Posted April 6, 2011 outputs this: Ore-tachi ni Tsubasa wa Nai - 01 Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/#findComment-1197684 Share on other sites More sharing options...
JAY6390 Posted April 6, 2011 Share Posted April 6, 2011 Not sure how you are getting the extra () unless something has been added, I get Ore-tachi ni Tsubasa wa Nai - 01 Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/#findComment-1197685 Share on other sites More sharing options...
Ortix Posted April 6, 2011 Author Share Posted April 6, 2011 whoops sorry about that. not sure where that came from but yeah. I would like to get Ore-tachi ni Tsubasa wa Nai 01 Without the dash between the Nai and 01 I put that in my initial post Maybe it can be done by finding the dash between a string and a number? Or perhaps the last instance of that character in the string? Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/#findComment-1197687 Share on other sites More sharing options...
JAY6390 Posted April 6, 2011 Share Posted April 6, 2011 Just put $result = str_replace('-', ' ', $result); After the preg_replace line Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/#findComment-1197689 Share on other sites More sharing options...
Ortix Posted April 6, 2011 Author Share Posted April 6, 2011 Yep that's it Link to comment https://forums.phpfreaks.com/topic/232858-weird-regex-question/#findComment-1197694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.