RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Get key value pairs separated by colon in a comma separated string
Expression
(?<key>[^\s]+(\s\w)*)(?=([\s]*:[\s]*))\2(?<=\2)(?<value>\b[^,:]+\b)
Description
Sometimes I want to store some key value mapped data in xml or text file, and then retrieve them into hashtable in program. Authough this can be done by split the string by comma and colon, and then trim the white space, I think regular expression should be easier. Note, the key must be single word or single white space separated words, and value can be any none colon or comma charactor serial.
Matches
" name a : hongfei jiang , gender: male, age :545 "
Non-Matches
name a : hongfei jiang
Author Rating: Not yet rated. jianghongfei
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials