I have a string like below
atom:link[@me="samiron" and @test1="t1" and @test2="t2"]
and I need a regular expression which will generate the following back references
#I would prefer to have
$1 = @test1
$2 = t1
$3 = @test2
$4 = t2
#Or at least. I will break these up in parts later on.
$1 = @test1="t1"
$2 = @test2="t2"
I’ve tried something like ( and [@\w]+=["\w]+)*\] which returns only last match and @test2="t2". Completely out of ideas. Any help?
Edit:
actually the number of @test1="t1" pattern is not fixed. And the regex must fit the situation. Thnx @Pietzcker.
This will give you hash which maps “@test1” => “t1” and so on:
Explanation: /g global match will give you an array of matches like
“@test1”, “t1”, “@test2”, “t2”, …
When hash %matches is assigned to this array, perl will automatically convert array to hash by treating it as key-value pairs.
As a result, hash %matches will contain what are you looking for in nice hash format.