Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 345879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:07:30+00:00 2026-05-12T11:07:30+00:00

I have an vCard application that needs to read vCard Data, and have found

  • 0

I have an vCard application that needs to read vCard Data, and have found a RegularExpression which gets the FieldName, Encoding and FieldValue from the file, here it is below:

^(?<FIELDNAME>[\w-]{1,})(?:(?:;?)(?:ENCODING=(?<ENC>[^:;]*)|CHARSET=(?<CHARSET>[^:;]*))){0,2}:(?:(?<CONTENT>(?:[^\r\n]*=\r\n){1,}[^\r\n]*)|(?<CONTENT>[^\r\n]*))

This Regular Expression Reads these kind of values fine:

ORG:Company
FN;ENCODING=QUOTED-PRINTABLE;CHARSET=UTF-8:RoguePlanetoid

However I want it to read these values also

TEL;WORK;VOICE:0200 0000000

Without skipping them. How can I modify the RegularExpression so TEL;WORK;VOICE ends up as part of the “FIELDNAME” and 0200 0000000 is part of the “CONTENT”.

I am unfamiliar with complex RegularExpressions and cannot figure out how to modify it, there is a regular expression that gets these:

^(?:TEL)([^:]*):(?<TEL>[^\r\n]*)

However it only gets the FieldName as “TEL” and I need the whole value for this so I can tell the numbers apart in my application.


If possible the Regular Expression would read the WORK and VOICE elements also like the CHARSET and ENCODING in the current regular expression, so they can treated like an Attribute and Type for example, however anything which allows the Regular Expression to read the whole TEL;WORK;VOICE as the FIELDNAME will be fine.


Edit

^(?<FIELDNAME>[^:]{1,})(?:(?:;?)(?:ENCODING=(?<ENC>[^:;]*)|CHARSET=(?<CHARSET>[^:;]*))){0,2}:(?:(?<CONTENT>(?:[^\r\n]*=\r\n){1,}[^\r\n]*)|(?<CONTENT>[^\r\n]*))

Reads up to the first Colon which covers the Whole FieldName, however it would be nice to store each SemiColon Element in a seperate item such as ATTRIBUTE or TYPE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:07:31+00:00Added an answer on May 12, 2026 at 11:07 am

    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.

    Regex r = new Regex(
        @"^(?<FIELD>[^\s:;]+)(;(?<PARAM>[^;:]+))*:(?<CONTENT>.*(?>\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);
    }
    

    EDIT: Now that I know where you got the regex from, 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.

    The author also allows for line folding, which probably does 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.

    I’ve revised my regex and added the Multiline modifier, which should have been there all along. :-/

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to read vCard and vCalendar data using .NET, I
I am creating an application which uses a vCard struct . Currently, this struct
Have an app that can use tts to read text messages. It can also
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have a n-tire web application and search often times out after 30 secs. How
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
I would like to be able to upload a vcard and have it parsed
I have a label that displays graphics card name, make and some other information,
I've recently been working on a vCard parser that opens a vCard file and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.