Perl regex problem on strings with several occurences of one char

Hi all,

i have the following line in a record file :

retenu=non
demande=non
script=#vtbackup /path=/save/backup/demande
position=140+70

and i want to use Perl regex to have the following output

key : "retenu" value : "non"
key : "demande" value "non"
key : "script"  value : "#vtbackup /path=/save/backup/demande"
key : "position" value : "140+70"

My problem is on the line "script...." and come from the 2 occurencies of equal sign.
I used index and substr to do the job, but i would like to do it using regex

Thank You for your help
--
Pat (France)

($key, $value) = m{^(.*?)=(.*)$};

You may want to get rid of leading and trailing whitespace with:

($key, $value) = m{^\s*(.+?)\s*=\s*(.*)\s*$};
1 Like

Great, THANK YOU :slight_smile: