I have a problem in preg_replace.
I have a text file which includes:
#define FWTE_BLACK "{000000FF
#define FWTE_TEST "{006600FF
...
The complete text is here : https://eval.in/133942
I would like to replace the ending FF
on each line to }"
Like this :
#define FWTE_BLACK "{000000}"
#define FWTE_TEST "{006600}"
...
您可以尝试以下方法:
preg_replace('/FF$/m', '}"', $file_string);
尝试这个:
$content = preg_replace('#FF$#', '}"' $content);
/\w{2}$/
<?php
$str = "#define FWTE_TEST \"{006600FF";
$pattern = '/\w{2}$/';
$replacement = '}"';
echo preg_replace($pattern, $replacement, $str);
?>
#define FWTE_TEST "{006600}"
Hope this help you!
Try :
preg_replace('/(.*)[F]{2}$/','$1}"','#define FWTE_BLACK "{000000FF');
Based on your comment this is the update:
echo preg_replace('/(.*)[F]{2}([\n\r])+/','$1}"$2',$myString);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.