str = "abc xyz asdf @ Rs1.5/day.poi qwerty."
我想在PHP中使用正则表达式并将其转换为"abc xyz asdf @ Re1/day.poi qwerty."
即,我想用"Rs1.5/day"
(比如s2)替换子串"Re.1/day"
(比如s1)
这里s1和s2可以是(Rs|Re)<digit>[.<digit>]/[<number>day(s)]
表达式应该如何?
答案 0 :(得分:1)
这是你的答案。
<?
$str = "abc xyz asdf @ Rs1.5/day.poi qwerty.";
print_r($str);
echo "<br />";
$newStr = preg_replace("/(\.[0-9]+)/", "", $str);
print_r($newStr);
?>
从数字或字符串中删除小数,数字为小数。
答案 1 :(得分:1)
怎么样:
$str = "abc xyz asdf @ Rs1.5/day.poi qwerty.";
$str = preg_replace("/Rs(\d+)(?:\.\d*)/", "Re$1", $str);
答案 2 :(得分:0)
我一直在寻找:
$str = "abc xyz asdf @ Rs1.5/day.poi qwerty.";
$rep = "(Rs|Re)?\s*\.?\s*\d*\.?\d+\/\d*days?"
$str = preg_replace($rep, "Re$1", $str)
谢谢!