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

  • SEARCH
  • Home
  • 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 7089143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:53:10+00:00 2026-05-28T07:53:10+00:00

I got a string with the following format : yyyyMMdd_HHmm_ss_unitCode_(status). I need to map

  • 0

I got a string with the following format : yyyyMMdd_HHmm_ss_unitCode_(status).
I need to map each component to a property of a dedicated class.

I thought of defining my token with a regular expression like this :
{d+}4{d+}2{d+}2_{d+}2_{d+}2_{s+}3_{s+}2 => Apologize for the approximate regex syntax, d is for decimal and s for string.

How can I tell my parser that the first group {d+}4 must go in the “year” property of my class, the second to the “month” and so forth.

Obviously, I could just do this : token.setYear(substring(0,4)) but I wanted to be a little more generic since I do not have control over the structure of the filename.
I also considered defining an xml structure with startPosition, endPosition, attribute name to store and type.

All in all, I thought all of this much too complicated. The problem is that I do not have a single separator to enable me to use a String.split.

  • 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-28T07:53:10+00:00Added an answer on May 28, 2026 at 7:53 am
    String input; // yyyyMMdd_HHmm_ss_unitCode_(status)
    SpecialClass output;
    
    String regex = "(\\d{4})(\\d{2})(\\d{2})_(\\d{2})(\\d{2})_(\\d{2})_([^_]+)_\\((.+)\\)";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(input);
    
    if (m.matches())
    {
        output.year = m.group(1);
        output.month = m.group(2);
        // etc
    }
    

    Example input:

    String input = "20120113_1234_27_500_(33)";
    

    Will produce the following groups:

    Group 1: 2012 //year
    Group 2: 01   //month
    Group 3: 13   //day
    Group 4: 12   //hour
    Group 5: 34   //minute
    Group 6: 27   //second
    Group 7: 500  //unitcode
    Group 8: 33   //status
    

    Test program: http://pastebin.com/upC5R9rP

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

Sidebar

Related Questions

I've got the following class: public static class Pages { public static string LoggedOut
I've got some data in the following format: -1,-1,-1,-1,701,-1,-1,-1,-1,-1,304,390,403,435,438,439,442,455 I need to insert it
I've got the following string: [global::System.CodeDom.Compiler.GeneratedCodeAttribute(System.Data.Design.TypedDataSetGenerator, 2.0.0.0)] I need to alter it to look
I got the following error : unable to format the string @( StudiesPatient.PatientName LIKE
I've got the following string : const std::string args = cmdLine=\-d ..\\data\\configFile.cfg\ rootDir=\C:\\abc\\def\; //
I've got the following code: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub
I got the following error of Oracle, ORA-25226: dequeue failed, queue string.string is not
so I've got the following structures; Start.master (Start.master.cs) Contains a Method DoSomething(string Text) {
I tried the following code in LINQPad and got the results given below: List<string>
I got a file which has dates stored as the following format (yyyy|dMM|dd). I

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.