neuroxik Posted March 9, 2010 Share Posted March 9, 2010 Hey everyone, I'm really bad with regex's but I tried and tried until finally I'm asking for help: I need to replace thousands of lines (I'm already looping each line break, all is okay for that) so that it replaces the numbers that are found within parentheses, like this: 1994-12-31 10 12 30 32 34 38 (39) 1994-12-28 10 21 22 27 28 43 (17) would give: 1994-12-31 10 12 30 32 34 38 1994-12-28 10 21 22 27 28 43 I've tried a whole bunch of combinations with preg_replace such as $s = preg_replace('/(\(00-99\))/','',$s); but nothing seems to work. As you can see I've escaped the parentheses ( & ) with backslashes so that they are not interpreted as delimiters, but it still doesn't strip the numbers in parentheses, which to some of you guys must be obvious because I must be missing out on something... Hope anyone can help. I hate to ask help so even if you point me to good reference, any help would be extremely appreciated. Thanks preg_replace('/(\(00-99\))/','',$s); Link to comment https://forums.phpfreaks.com/topic/194577-stripping-parentheses-and-the-numbers-inside/ Share on other sites More sharing options...
gizmola Posted March 9, 2010 Share Posted March 9, 2010 I had to make a few assumptions from your post, but this seems to be in the right ballpark. This will of course replace (23) but not (231) nor (1). Seemed to be what you were going for. If any number of digits inside the () should get stripped then you'd want d+ rather than d{2}. $s = preg_replace('/\(\d{2}\)/','',$s); Link to comment https://forums.phpfreaks.com/topic/194577-stripping-parentheses-and-the-numbers-inside/#findComment-1023438 Share on other sites More sharing options...
neuroxik Posted March 9, 2010 Author Share Posted March 9, 2010 I had to make a few assumptions from your post, but this seems to be in the right ballpark. This will of course replace (23) but not (231) nor (1). Seemed to be what you were going for. If any number of digits inside the () should get stripped then you'd want d+ rather than d{2}. $s = preg_replace('/\(\d{2}\)/','',$s); Wow, it worked! Thanks so much! Link to comment https://forums.phpfreaks.com/topic/194577-stripping-parentheses-and-the-numbers-inside/#findComment-1023677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.