Jump to content

a123123

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

a123123's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello I have the following code: <?php $patterns = array('/(?s)(?<=\s)(\s|,|\\\|\^|\(|\)|\[(?!t)|(?<!t)\]|{|}|0-9|\-|\=|\+|b|c|d|f|g|h|j|k|l|m|n|p|r|s|(?<!t)x|B|C|D|F|G|H|J|K|L|M|N|P|R|S|T|X|.\(.\)|)+(?=(\s|\.)(??!\[\/t\]).|\n)*\[te\])/'); $replacements = array('[t]$1[/t]'); $string=$_POST['kod']; echo preg_replace($patterns, $replacements, stripslashes($string)); ?> I want it to: 1) dot matches newline 2) every string which is followed by space or newline and contains: coma, backslash \, ^, (, ), [, ], {, }, digits, -, =, +, small and big letters, every .(.) series, and is between [/t] and [t] characters (example: [/t] ... string ... [t]), would be changed to [t]$1[/t]. But it doesn't work - only newlines are changed. Where is a problem?
  2. It was very helpless for me, I've done it and the problem is solved thank you very much sorry for my English where I can mark that the topic is solved? I remember that here used to be such an option
  3. I have problem with this code: <?php $patterns = array('/(?<=\s)(\s|,|\+|frac|cdot|begin|cases|end|\^|\(|\)|\[|\]|\{|\}|\d|\-|\=|(?<=\+|\-|\=)(a|e|i|o|u|y)|b|c|d|f|g|h|j|k|l|m|n|p|r|s|t(?!ex)|(?<!te)x|B|C|D|F|G|H|J|K|L|M|N|P|R|S|T|X|.\(.\)|^\[t\]|^\[\/t\])+(?=(\s|,|\.|\?|\!|\(??!\[\/tex\]).|\n)*\[t\])/'); $replacements = array('($1)'); $string=$_POST['kod']; echo preg_replace($patterns, $replacements, $string); ?> Why it changes one backslash: \ into two: \\? Thanks for answer.
  4. Thanks for answer. It is the same in both cases ' ' and " ". The problem is about quantity - I need to change every sets of \n, it means \n+, to b letter. It changes, but not to one - one \n changes to one b, two \n to bb, three \n to bbb, and so on. Any way to fix it?
  5. quickly and helpful answer, thanks this is the only thing which I need to do, and this grouping looks nice. It works for me. I am a bit unexperienced in regexp, and I can do many unnecessary things. I liked these forums. You are really helpful. It was all what I needed, and there is no other point what I am missing
  6. Thanks for answer. It works for not special signs. Why doesn't it work with ex. \n (newline)?
  7. Thanks for answer and help. I'm sorry, but I cant understand what more could I explain, may I ask for asking more specific question? What is ${1} for? Is it repetition of the same element?
  8. Hello. I need to change every string: aa aaa aaaa in general: a{1,} to b - independent of a quantity, there should be only one b. Do you have any ideas to do it?
  9. Okay, sorry. I want to change every string like: # ab . cd $ to 3 ab . cd 4, example lets find some random strings: # 123 . abc $ # 456 . asd $ # 147 . qwe $ # 123 . zxc $ 123 # and I want to change #->3 and $->4 only in strings which are this form. String 123 # shouldn't be changed. The result should be: 3 123 . abc 4 3 456 . asd 4 3 147 . qwe 4 3 123 . zxc 4 123 # I solved problem #->3 with positive lookahead, and if positive lookbehind could be various length, it would be solved also for $->4. Any other ideas?
  10. Sorry for double post, but I have a last question about this thing. Now look behind: '/(?<=#.*?\..*?)\$/' and says it has no fixed length - where is it wrong? thanks
  11. Thanks for the name "negative lookbehind". I concluded that in this case it must be something like "look forward", I found "look ahead" and it is much more clear now. I am going to try to do this and I will ask if I get problems. Thank you very much. All that I needed was "positive lookahead". The code that worked for me was: '/\#(?=.*?\..*?$)/'
  12. Thanks for all the answers. The code I am using is: <?php $patterns = array('/(?<!e)abcd/'); $replacements = array('abcde'); $string=$_POST['link']; echo preg_replace($patterns, $replacements, $string); ?> and when I have negation on the beginning of the string, it is good, becaise when I have string ex. habcd, it changes to habcde, and h is remaining. But if I place it on the end of the string, ex. abcd(?<!e), string like abcdh changes to abcde, while I need abcdeh (h not disappearing). I hope that it will be more clear now. What is ~ and ? for in this code? $string = preg_replace('~#(.*?\..*?\$)~', '3\1', $string); and what is for + here? '/#(.+\..+$)/'
  13. Hey. I need to replace one particular sign only if it is part of specified string. In this case it is: # ab . cd $ where ab, cd are any random string, and there is dot which divides them. So if I had a string # abcd, without dot and $, it should not change. But if it is like # ab . cd $ # changes into 3. This what I got was changing the whole string to 3, but I need 3 ab . cd $ - how can I do it?
  14. Hello. Lets find some random string that I need to replace, ex. # ab . cd $. And I want to change # to 3 and $ to 4 only if it is in this form of string. I write rexexp pattern: '/#(.*)(.)(.*)($)/' and replacement: 3 but why the whole string is replaced to 3, not only #? How can I change my string to 3 ab . cd $?
  15. Well, I found answer, its triple backslash. I think I mark it as solved and make another topic because my new problem is similar. Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.