ikin Posted November 4, 2010 Share Posted November 4, 2010 Well I have never learn'd Regex, so I need some help with it. I'm trying to remove the |file = in the string (the code is in wikipedia format): {{Infobox Music |name = Body Parts |release = [[31 January]] [[2005]] |update = Creature of Fenkenstrain |members = Yes |location = Experiment Dungeon |skillrequired = |questrequired = [[Creature of Fenkenstrain]] |hint = This track unlocks at the dungeon south-east of Fenkenstrain's Castle. |file = }} oh if it were just to do str_replace it would be love but no, they have to use multi spaces sometimes :@... Like: | file = Etc but only spaces nothing else, So I was trying to replace it (as I said): echo(preg_replace("/(\|)(\s+)(\file)(\s+)(\=)/i", "", $e)); But it didn't work (Yes I tried with many...) So I come here to ask for help. Thanks for reading. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 4, 2010 Share Posted November 4, 2010 $result = preg_replace('/\|\s*file\s*=/im', '', $e); Quote Link to comment Share on other sites More sharing options...
ikin Posted November 4, 2010 Author Share Posted November 4, 2010 oo, fast answer. Thank you so much Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 4, 2010 Share Posted November 4, 2010 No problem Quote Link to comment Share on other sites More sharing options...
salathe Posted November 4, 2010 Share Posted November 4, 2010 You were nearly there. \f means something special when within a double-quoted string, just remove that slash and it would have worked. For what it's worth, you also (obviously, after JAY6390's post) need any of the parentheses nor a slash before the equals character. It would also be good to "anchor" the expression so that the | can only be matched at the start of a line. Also, read up on the m pattern modifier that JAY6390 introduced and see if you think it is necessary or not. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 4, 2010 Share Posted November 4, 2010 I did actually mean to put in the ^ anchor, oops. True the | doesn't need a \ before it, but only if the ^ is before it. if left without the ^ anchor and no \ before the |, it won't be a valid regex. I generally escape all special characters just out of habit to be honest, even when not needed inside character classes etc Quote Link to comment Share on other sites More sharing options...
salathe Posted November 4, 2010 Share Posted November 4, 2010 True the | doesn't need a \ before it No-one said it doesn't (it does). Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 4, 2010 Share Posted November 4, 2010 Upon second inspection, no they did not Clearly today has been too long already lol Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.