The Little Guy Posted March 10, 2009 Share Posted March 10, 2009 Is there a way to say: replace "a" unless it is between "b" and "c"? Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/ Share on other sites More sharing options...
.josh Posted March 10, 2009 Share Posted March 10, 2009 yes, with lookaround Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-781683 Share on other sites More sharing options...
The Little Guy Posted March 11, 2009 Author Share Posted March 11, 2009 What is a look around, and how would I use it? Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-781758 Share on other sites More sharing options...
effigy Posted March 11, 2009 Share Posted March 11, 2009 http://www.regular-expressions.info/lookaround.html Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-782070 Share on other sites More sharing options...
The Little Guy Posted March 11, 2009 Author Share Posted March 11, 2009 Thanks for the link, Ill look at it! Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-782254 Share on other sites More sharing options...
The Little Guy Posted March 11, 2009 Author Share Posted March 11, 2009 WOW, I'm totally confused. Here is my array of "finds" $find = array( '~(\s[a-z].*?=)~', // Highlight the attributes '~(<\!--.*?-->)~s', // Hightlight comments '~("[a-zA-Z0-9\/].*?")~', // Highlight the values '~(<[a-z].*?>)~', // Highlight the beginning of the opening tag '~(</[a-z].*?>)~', // Highlight the closing tag '~(&.*?~', // Stylize HTML entities ); For the values line, I place this in front of what I have: (?!=<\!--) So then I would have this: ~(?!=<\!--)("[a-zA-Z0-9\/].*?"~ Is that how it is done? If so, It isn't doing anything, as you can see from this result here (first four lines should be commented out): http://phpsnips.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-782429 Share on other sites More sharing options...
effigy Posted March 12, 2009 Share Posted March 12, 2009 ?! means does not follow. ?= means follows. ?!=, what you have, means does not follow, then a literal =. Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-783160 Share on other sites More sharing options...
The Little Guy Posted March 12, 2009 Author Share Posted March 12, 2009 I think that is what I want... What I am hopping, is for it to say "don't apply the formatting if it is within a HTML comment" Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-783243 Share on other sites More sharing options...
MadTechie Posted March 13, 2009 Share Posted March 13, 2009 example $data = "bac abc cab"; $data = preg_replace('/(?<!b)a(?!c)/sm', 'X', $data ); echo $data; //bac Xbc cXb Quote Link to comment https://forums.phpfreaks.com/topic/148814-replace-unless/#findComment-784004 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.