PHP question - regular expressions, string replacement.
Does anyone know how I could replace a string that starts with a certain character, and ends with a certain character, but has any number of, and combination of, other characters in between. I think it can be done with regular expressions, but haven't used them very much before.
BTW, in case you didn't read the title, I'm using PHP.
you can use substring string manipulation functions as well,for RegExp..hunmm..PM pyro..
var re = /^A.*Z$/; //set up reg exp to start with an uppercase A and end with an uppercase Z and take anything and everything in between
var mystring = "Ad3f24fj-@%(}lZ"; //string to replace
var mynewstring = mystring.replace(re, "yourreplacement") //replace mystring with "yourreplacement"
Does anyone know if there is a PHP way to do this, as I am using PHP for the rest of the operation?
Oh boy... I didn't read you question very well... Here is the PHP version. (untested)
NOTE: if that doesn't work, let me know, and I'll get you a tested version... right now I'm in a hurry.
$re = /^A.*Z$/; //set up reg exp to start with an uppercase A and end with an uppercase Z and take anything and everything in between
$mystring = "Ad3f24fj-@%(}lZ"; //string to replace
$mynewstring = str_replace($re, "yourreplacement", $mystring) //replace mystring with "yourreplacement"
Don't you need to use ereg_replace to use regular expressions? I can't get your code to work - any ideas why, or other things I could try?
I have the replace feature working, but I have a new problem. How would I make it allow any character in between the two letters, rather than just the alphabet and numbers? I need to be able to allow basically every character.
Never mind, I got it! Thanks for all of your help.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)