Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe this does what you want. It's in C# because I'm not set up to test VB, but you shouldn't have any trouble converting it.</p> <pre><code>Regex r = new Regex( @"^(?&lt;FIELD&gt;[^\s:;]+)(;(?&lt;PARAM&gt;[^;:]+))*:(?&lt;CONTENT&gt;.*(?&gt;\r\n[ \t].*)*)$", RegexOptions.ExplicitCapture | RegexOptions.Multiline); string target = @"TEL;WORK;VOICE:0200 0000000"; Match m = r.Match(target); if (m.Success) { Console.WriteLine("field name: {0}", m.Groups["FIELD"].Value); foreach (Capture c in m.Groups["PARAM"].Captures) { Console.WriteLine(" type: {0}", c.Value); } Console.WriteLine("content: {0}", m.Groups["CONTENT"].Value); } </code></pre> <p>EDIT: Now that I know <a href="http://blog.smithfamily.dk/CategoryView,category,vcard.aspx" rel="nofollow noreferrer">where you got the regex from</a>, I can see the author is trying to do too much work in the regex. "Encoding" and "charset" are just two of many possible parameter names; I don't see any reason to match those two by name and not any others. Just iterate through the "PARAM" captures like I did and handle each one as appropriate.</p> <p>The author also allows for line folding, which probably <em>does</em> belong in the regex. The rules governing line folding seem pretty simple: if a line starts with a space or a tab, it's a continuation of the previous line. That also means the "FIELD" subexpression needs to be revised to disallow whitespace as well as colons and semicolons. </p> <p>I've revised my regex and added the Multiline modifier, which should have been there all along. :-/</p> <p>I feel I should mention that, if you're writing a complete vCard processing app, you probably shouldn't be building it on top of regexes. A non-regex solution will be easier to write (though not as much fun) and easier to maintain.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload