简体   繁体   中英

How to make php match regex NOT matching over lines?

My code is

preg_replace("/([^; ]+)=>([^; ]+)/", "ec_set('$1',$2);", $input_lines);

on matching the following text

test=>1; test; test=>123; 

asdf
test=>[[test]]

The result

is outputting over-lines

ec_set('test',1);; test; ec_set('test',123);; ec_set('

asdf
test',[[test]]);

How to make it

ec_set('test',1);; test; ec_set('test',123);; 

asdf
ec_set('test',[[test]]);

?

([^;\s]+)=>([^;\s]+)

Try this.See demo.

https://regex101.com/r/vH0iN5/4

尝试这个:

preg_replace("/([^;\\n ]+)=>([^;\\n ]+)/", "ec_set('$1',$2);", $input_lines);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM