dechamp Posted May 21, 2010 Share Posted May 21, 2010 I'm not understanding what I'm doing wrong and I'm really tired which is my first problem. Solve this for me please! $input = "why won't you change my word. @@origionalWord@@"; $q = "@@{1}[[:word:]]*@@{1}"; $input2 = str_replace($q, 'replacementWord', $input); This is not changing it to "why won't you change my word. replacementWord I've used an regexp gen to verify my work and it's still not working. I tried a ton of different variations. (@@{1}[[:word:]]*@@{1}) (@@){1}[[:word:]]*(@@){1} ((@@){1}[[:word:]]*(@@){1}) and so on. also with ^ and $ Link to comment https://forums.phpfreaks.com/topic/202468-frickin-damn-regexp-please-help-me-before-i-shoot-myself/ Share on other sites More sharing options...
cags Posted May 21, 2010 Share Posted May 21, 2010 Firstly str_replace doesn't support complex matching (i.e. Regular Expressions), it only matches literal strings. Secondly the syntax you are using there looks very much like POSIX, ideally you should be using PCRE syntax with the preg_ functions such as preg_match. To replace literal '@@originalWord@@' $output = str_replace('@@originalWord@@', 'replacementWord', $intput; To replace any word between double @ signs $output = preg_replace('#@@[a-z]+@@#i', 'replacementWord', $input); Link to comment https://forums.phpfreaks.com/topic/202468-frickin-damn-regexp-please-help-me-before-i-shoot-myself/#findComment-1061510 Share on other sites More sharing options...
ignace Posted May 21, 2010 Share Posted May 21, 2010 Before shooting yourself, read up on Regex and PHP Regex functions. str_replace() is not one of 'em. $text = 'why won\'t you change my word. @@origionalWord@@'; echo preg_replace('/@@([a-z])+@@/i', 'replacementWord', $text); Edit: meh Link to comment https://forums.phpfreaks.com/topic/202468-frickin-damn-regexp-please-help-me-before-i-shoot-myself/#findComment-1061518 Share on other sites More sharing options...
dechamp Posted May 21, 2010 Author Share Posted May 21, 2010 Wow and this is why working exhausted is a bad idea, I started off with preg_match and throughout testing totally forget that I had tried using str_repace. grrrrr well thank you both for the help! Link to comment https://forums.phpfreaks.com/topic/202468-frickin-damn-regexp-please-help-me-before-i-shoot-myself/#findComment-1061625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.