次の文字列があります
someText 50-90% someText
文字列がこのような形式であっ%
た場合の後に追加したいだけです50
someText 50%-90% someText
私は次のことを試しました...
preg_replace('/(\d+)\-[\d]+%/','$0%', 'text 30-50% text')
//the output: text 30-50%% text
preg_match_all('/(\d+)\-[\d]+%/', 'text 30-50% text',$x)
/*$x = array(2) {
* [0]=>
* array(1) {
* [0]=>
* string(6) "30-50%"
* }
* [1]=>
* array(1) {
* [0]=>
* string(2) "30"
* }
*}
*/
preg_replace('/(\d+)\-[\d]+%/','$1%', 'text 30-50% text');
//the output: text 30% text