1

Let's assume this paths:

"...../site/configurationEN/database"
"....../site/configurationDE/database"
"....../site/configurationFR/database"
...
"....../site/configurationXX/database"

where XX can have many values for many countries.

How can i remove the XX characters from my path using regex replace and PHP? I need an expresion that would change any of the strings above in :

"....../site/configuration/database"

Thank you!

maephisto
  • 4,952
  • 11
  • 53
  • 73
  • take a look at the `preg_replace()` function: http://php.net/manual/en/function.preg-replace.php – Grambot Jan 08 '13 at 18:35
  • See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Jan 08 '13 at 18:38

1 Answers1

1

Try that :

<?php
$path = "site/configurationDE/database";
$newPath = preg_replace('#^(.*site/configuration)[A-Z]{2}#', '$1', $path);
?>
Vince
  • 3,274
  • 2
  • 26
  • 28
  • thanks! I made a small edit - added "....../" because i'm not sure what the path will be - i am sure online that it will exist a folder /configurationXX/ – maephisto Jan 08 '13 at 18:45
  • Sure, i already did it. Can you update the answer so it will fit the changed strings? – maephisto Jan 08 '13 at 18:57