I could not solve below problem so I used Perl script to parse
without regular expression, but I believe there’s a regular expression for it.
Input String (there’s no newline):
ObjectAddress=120.146.128.250,ObjectName=psyseds-tt1y,ObjectClass=SCM F5,ObjectDescription=,Aliases=psyseds-tt1y.site.com.,NameService=A,PTR,DynamicDNSUpdate=A,PTR,CNAME
Expected Output:
ObjectAddress=120.146.128.250
ObjectName=psyseds-tt1y
ObjectClass=SCM F5
ObjectDescription=
Aliases=psyseds-tt1y.site.com.
NameService=A,PTR
DynamicDNSUpdate=A,PTR,CNAME
I tried some regular expression to parse string, but I failed to parse
since it has multiple items with , separated value.
For example, NameService has two value A,PTR.
Please help me to build regular expression to parse above.
(.+?=.*?) does not pick up multiple values.
In general, it doesn’t seem that your format is unambiguous — something like
A=B,C=Dcould mean either thatAmaps toBandCmaps toD, or thatAmaps toB,C=D— but for a good approximation, you can write:this will split
$inputon commas (,), with the added restriction that the comma must be followed by one or more “word characters” (\w— letters, digits, underscores) plus an equals sign. (This is called a lookahead assertion.)