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

Please support RegExLib Sponsors

Sponsors

Expressions by User

   Displaying page 1 of 1 pages; Items 1 to 1
Title Test Details 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
   Displaying page 1 of 1 pages; Items 1 to 1

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