Domanda

I want to generate regex for vCard Properties.

For Ex:

VERSION:

Regex regex = new Regex(@"(?<strElement>(VERSION))   (:(?<strVERSION>[^\n\r]*))", options);
 Match  m = regex.Match(s);

how to write other vcard proparty like ADR,AGENT,PHOTO,ETC...

http://en.wikipedia.org/wiki/VCard#hCard_1.0

È stato utile?

Soluzione

For such straightforward format it is better to avoid regexps and use simple string operations. For example, the text can be splited by \n and then each line can be splited by semicolon.

If you want to continue with regexps, try to replace VERSION with \w+ and " " with " *". I also not sure that the second grouping is necessary. Also, the ^ and $ can be added (the multiline regex option should be used then):

@"^(?<strElement>(\w+)) *:(?<strVERSION>.*)$"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top