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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:43:44+00:00 2026-05-22T21:43:44+00:00

I am in need of a regular expression that I can use to examine

  • 0

I am in need of a regular expression that I can use to examine a string and return specific items when I do a RegEx.Split() in .NET. I’ve been trying to do this on my own, but I can never seem to get what I need, and the results never make any sense. Obviously I do not have a good handle on writing regular expressions.

So here is the string…

"%date - %-5level - [%thread] - %logger - %message - %exception%newline"

I essentially want to be returned an array that looks like the following:

"date"
"-5level"
"thread"
"logger"
"message"
"exception"
"newline"

The following code is close, but not quite.

Regex exp = new Regex(@"\W+");
string[] s = exp.Split(@"%date - %-5level - [%thread] - %logger - %message - %exception%newline");

I get the following:

""
"date"
"5level"
"thread"
"logger"
"message"
"exception"
"newline"

For some reason, I have an empty string as the first index, and the 3rd index is missing the “-“. I assume because it is not a part of a “word”.

The “-” aside for the moment, I then want to split “5level” into an array:

"5"
"level"

I experimented with this:

Regex exp2 = new Regex(@"(\d+)([a-zA-Z]+)");
string[] s2 = exp2.Split("5level");

But, it returns 2 indexes with empty strings in addition to the split items I want like so:

""
"5"
"level"
""

I’m stumped on how to format the expression to give me what I need. Any help would be appreciated.

  • 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-22T21:43:45+00:00Added an answer on May 22, 2026 at 9:43 pm

    Instead of using Regex.Split, it might be easier to match the tokens you need:

    MatchCollection matches = Regex.Matches(s, @"%([\w\-]+)");
    string[] words = matches.Cast<Match>().Select(m => m.Groups[1].Value).ToArray();
    

    Split may add empty matches, as you’ve witnessed, that will have to be filtered out.

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

Sidebar

Related Questions

I need a regular expression that I can use in VBScript and .NET that
When given a full URL I need a regular expression that I can use
I'm need a regular expression in Java that I can use to retrieve the
I'm in need of a regular expression that can remove unnecessary/extra parenthesis in a
I need a .NET regular expression that matches anything other than the exact full
Can anyone help me with a javascript regular expression that I can use to
Can anyone help me with a regular expression that will return the end part
How can I convert a string to a regular expression that matches itself in
I need help with a regular expression for use with UrlRewriting.Net. I have two
I need to create a regular expression that allows a string to contain any

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.