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 8095967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:18:38+00:00 2026-06-05T21:18:38+00:00

I have a string which is in the following format, When there is a

  • 0

I have a string which is in the following format, When there is a match the regex.macth static method runs pretty quickly. However often at times there will be a string which will not match and I was running some scenarios and it goes into backtracking and regex.match never seems to end. that specific case when the fields were not in order and some of the fields were not there. i have to use regex and was wondering if someone has any tips? Also I am only retrieving a few groups values for instance 7.
Okay my data looks like the above, when It matches exaclty it runs fine, forexample 100 hundred of this no problem and I am satisfied with that, When the format could be different for instance some of the fields for example the last four ones are not there or some of the fileds are ordered differenty, in this regex.match just runs forever. In this case if the format is not as my static string, I just want to end the process.

  • 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-06-05T21:18:39+00:00Added an answer on June 5, 2026 at 9:18 pm

    I don’t have your data where I could test a failure.

    Update

    Thanks for the sample, I see the problem now. Basically, the regex has overlapping sets that are optionally matching. This is the subexpression \s*([^}]*?). When overlapping character classs like these are combined, it can be a reciepe for catastrophic backtracking. In this case the regex is awash with whitespace references.

    The solution is to force certain parts to not give back to the backtracker when an optional part doesn’t benefit from backtracking (but only hurts it). Making a section atomic has the affect of making it a literal. In this case the trimming sections are causing problems, remove them from backtracking and it fixes the problem.

    But, in order to trim correctly, the \s* expression needs to be alterred.

    @Alan Moore mentions there is no possesive quantifiers in .NET.
    He’s right, so use the ‘Atomic Grouping’ regex below.

    Atomic Grouping version:

    TEST_REPLICATE\s*{\s*REPLICATE_ID(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*ASSAY_NUMBER(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*ASSAY_VERSION(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*DILUTION_ID(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*SAMPLE_ID(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*SAMPLE_TYPE(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*TEST_ORDER_DATE(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*TEST_ORDER_TIME(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*TEST_INITIATION_DATE(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*TEST_INITIATION_TIME(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*TEST_COMPLETION_DATE(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*TEST_COMPLETION_TIME(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*ASSAY_CALIBRATION_DATE(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*ASSAY_CALIBRATION_TIME(?>[^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]*)\s*RESULT_INTERPRETATION(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*DILUTION_PROTOCOL(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*RESULT_COMMENT(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*DATA_MANAGEMENT_FIELD_1(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*DATA_MANAGEMENT_FIELD_2(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*DATA_MANAGEMENT_FIELD_3(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*DATA_MANAGEMENT_FIELD_4(?>[^\S\n]*)([^}\n]*?)(?>[^\S\n]*)\s*}
    

    Possesive quantifiers Version:

    TEST_REPLICATE\s*{\s*REPLICATE_ID[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*ASSAY_NUMBER[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*ASSAY_VERSION[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*DILUTION_ID[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*SAMPLE_ID[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*SAMPLE_TYPE[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TEST_ORDER_DATE[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TEST_ORDER_TIME[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TEST_INITIATION_DATE[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TEST_INITIATION_TIME[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TEST_COMPLETION_DATE[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TEST_COMPLETION_TIME[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*ASSAY_CALIBRATION_DATE[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*ASSAY_CALIBRATION_TIME[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*TRACK[^\S\n]*+([^}\n]*?)[^\S\n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ENT_FIELD_2[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*DATA_MANAGEMENT_FIELD_3[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*DATA_MANAGEMENT_FIELD_4[^\S\n]*+([^}\n]*?)[^\S\n]*+\s*}
    

    Expanded with group numbers:
    (this may be a bit painfull to look at)

         TEST_REPLICATE\s*
         {\s*
         REPLICATE_ID
         (?> [^\S\n]* )
    1    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*ASSAY_NUMBER
         (?> [^\S\n]* )
    2    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*ASSAY_VERSION
         (?> [^\S\n]* )
    3    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DILUTION_ID
         (?> [^\S\n]* )
    4    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*SAMPLE_ID
         (?> [^\S\n]* )
    5    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*SAMPLE_TYPE
         (?> [^\S\n]* )
    6    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TEST_ORDER_DATE
         (?> [^\S\n]* )
    7    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TEST_ORDER_TIME
         (?> [^\S\n]* )
    8    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TEST_INITIATION_DATE
         (?> [^\S\n]* )
    9    ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TEST_INITIATION_TIME
         (?> [^\S\n]* )
    10   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TEST_COMPLETION_DATE
         (?> [^\S\n]* )
    11   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TEST_COMPLETION_TIME
         (?> [^\S\n]* )
    12   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*ASSAY_CALIBRATION_DATE
         (?> [^\S\n]* )
    13   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*ASSAY_CALIBRATION_TIME
         (?> [^\S\n]* )
    14   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*TRACK
         (?> [^\S\n]* )
    15   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*PROCESSING_LANE
         (?> [^\S\n]* )
    16   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*MODULE_SN
         (?> [^\S\n]* )
    17   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*LOAD_LIST_NAME
         (?> [^\S\n]* )
    18   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*OPERATOR_ID
         (?> [^\S\n]* )
    19   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DARK_SUBREADS
         (?> [^\S\n]* )
    20   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*SIGNAL_SUBREADS
         (?> [^\S\n]* )
    21   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DARK_COUNT
         (?> [^\S\n]* )
    22   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*SIGNAL_COUNT
         (?> [^\S\n]* )
    23   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*CORRECTED_COUNT
         (?> [^\S\n]* )
    24   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*STD_BAK
         (?> [^\S\n]* )
    25   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*AVG_BAK
         (?> [^\S\n]* )
    26   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*STD_FOR
         (?> [^\S\n]* )
    27   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*AVG_FOR
         (?> [^\S\n]* )
    28   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*SHAPE
         (?> [^\S\n]* )
    29   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*EXCEPTION_STRING
         (?> [^\S\n]* )
    30   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*RESULT
         (?> [^\S\n]* )
    31   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*REPORTED_RESULT
         (?> [^\S\n]* )
    32   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*REPORTED_RESULT_UNITS
         (?> [^\S\n]* )
    33   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*REAGENT_MASTER_LOT
         (?> [^\S\n]* )
    34   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*REAGENT_SERIAL_NUMBER
         (?> [^\S\n]* )
    35   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*RESULT_FLAGS
         (?> [^\S\n]* )
    36   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*RESULT_INTERPRETATION
         (?> [^\S\n]* )
    37   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DILUTION_PROTOCOL
         (?> [^\S\n]* )
    38   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*RESULT_COMMENT
         (?> [^\S\n]* )
    39   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DATA_MANAGEMENT_FIELD_1
         (?> [^\S\n]* )
    40   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DATA_MANAGEMENT_FIELD_2
         (?> [^\S\n]* )
    41   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DATA_MANAGEMENT_FIELD_3
         (?> [^\S\n]* )
    42   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*DATA_MANAGEMENT_FIELD_4
         (?> [^\S\n]* )
    43   ( [^}\n]*? )
         (?> [^\S\n]* )
         \s*}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a string which has the following format (3,1,Mayer,Jack). I need all 4
I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I have the following string which will probably contain ~100 entries: String foo =
Quick question, I have the following string which is a coma separated list of
I have the following string from which I want to extract gcc-4.3.2 and C
So I have the following connection string which is causing me issues. I am
I Have a object which the following field : boost::unordered_map<std::string, std::shared_ptr<Foo> > m_liste_; I
I have the following string as a variable: var name1 = '001-C6AL7_deepgreen_C3AE7_tankhakinavy_FJAG7_blackredmulti_FBAE7_tanbrown.jpg'; Which is
I have a table in db2 which has the following fields int xyz; string
I have vb.net application which is using Vistadb with following connection string. I am

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.