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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:07:18+00:00 2026-06-02T05:07:18+00:00

I’m trying to split the following string Name==’mynme’ && CurrentTime<‘2012-04-20 19:45:45’ into this: Name

  • 0

I’m trying to split the following string "Name=='mynme' && CurrentTime<'2012-04-20 19:45:45'" into this:

Name
==
'myname'
&&
CurrentTime
<
'2012-04-20 19:45:45'

I have the following regex:

([+\\-*/%()]{1}|[=<>!]{1,2}|[&|]{2})

The problem is when using the above regex I get the following result:

Name
== 
'myname'
&&
CurrentTime 
<
'2012
-
04
-
20
19:45:45'

I practically need the regex to be quote aware.

Thanks

Update 1 regarding lordcheeto’s answer:

Your response is close. But the following is still not split correctly:

 string input2 = "((1==2) && 2-1==1) || 3+1==4 && Name=='Stefan+123'";

What I need to do is to split a string into operators and operands. Something like this:

 LeftOperand Operator RightOperand

Now, if any operator is between '' it should be ignored and the whole string between '' should be treated as an operand.

The string above should generate the following output:

(

(
1
==
2
)

&&
2
-
1
==
1
)

||
3
+
1
==
4
&&
Name
==
'Stefan+123'
  • 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-02T05:07:20+00:00Added an answer on June 2, 2026 at 5:07 am

    Ok, assuming you want it to simply split on logical and relational operators, you can use this pattern:

    string lordcheeto = @"\s*(==|&&|<=|>=|<|>)\s*";    
    

    This will also trim all whitespace from the returned strings.

    Code:

    using System;
    using System.Text.RegularExpressions;
    
    namespace RegEx
    {
        class Program
        {
            static void Main(string[] args)
            {
                string original = "([+\\-*/%()]{1}|[=<>!]{1,2}|[&|]{2})";
                string lordcheeto = @"\s*(==|&&|<=|>=|<|>)\s*";
    
                string input = "Name=='mynme' && CurrentTime<45 - 4";
                string input1 = "Name=='mynme' && CurrentTime<'2012-04-20 19:45:45'";
                string ridiculous = "Name == BLAH && !@#>=$%^&*()< ASDF &&    this          >          that";
    
                executePattern("original", input, original);
                executePattern("lordcheeto's", input, lordcheeto);
                executePattern("original", input1, original);
                executePattern("lordcheeto's", input1, lordcheeto);
                executePattern("original", ridiculous, original);
                executePattern("lordcheeto's", ridiculous, lordcheeto);
            }
    
            static void executePattern(string version, string input, string pattern)
            {
                // Avoiding repitition for this example.
                Console.WriteLine("Using {0} pattern:", version);
    
                // Needs to be trimmed.
                var result = Regex.Split(input.Trim(), pattern);
    
                // Pipes included to highlight whitespace trimming.
                foreach (var m in result)
                    Console.WriteLine("|{0}|", m);
    
                // Extra space.
                Console.WriteLine();
                Console.WriteLine();
            }
        }
    }
    

    Test:

    http://goo.gl/XAm6J

    Output:

    Using original pattern:
    |Name|
    |==|
    |'mynme' |
    |&&|
    | CurrentTime|
    |<|
    |45 |
    |-|
    | 4|
    
    
    Using lordcheeto's pattern:
    |Name|
    |==|
    |'mynme'|
    |&&|
    |CurrentTime|
    |<|
    |45 - 4|
    
    
    Using original pattern:
    |Name|
    |==|
    |'mynme' |
    |&&|
    | CurrentTime|
    |<|
    |'2012|
    |-|
    |04|
    |-|
    |20 19:45:45'|
    
    
    Using lordcheeto's pattern:
    |Name|
    |==|
    |'mynme'|
    |&&|
    |CurrentTime|
    |<|
    |'2012-04-20 19:45:45'|
    
    
    Using original pattern:
    |Name |
    |==|
    | BLAH |
    |&&|
    | |
    |!|
    |@#|
    |>=|
    |$|
    |%|
    |^&|
    |*|
    ||
    |(|
    ||
    |)|
    ||
    |<|
    | ASDF |
    |&&|
    |    this          |
    |>|
    |          that|
    
    
    Using lordcheeto's pattern:
    |Name|
    |==|
    |BLAH|
    |&&|
    |!@#|
    |>=|
    |$%^&*()|
    |<|
    |ASDF|
    |&&|
    |this|
    |>|
    |that|
    

    Edit

    Ok, with the additional constraints, you should be able to use this:

    string lordcheeto = @"\s*('.*?'|&&|==|<=|>=|<|>|\(|\)|\+|-|\|\|)\s*";
    

    This will still trim all whitespace from the returned strings. It will, however, return empty strings if matches are right next to each other (e.g. Name=='Stefan+123'). I was unable to work around that this time, but it’s not so important.

    If you import System.Linq and System.Collections.Generic and make the results a List<string>, you can remove all empty strings from the List in one extra line like this (which is slower than using straight-up for loops):

    var results = Regex.Split(input.Trim(), pattern).ToList();
    results.RemoveAll(x => x == "");
    

    Code:

    using System;
    using System.Text.RegularExpressions;
    
    namespace RegEx
    {
        class Program
        {
            static void Main(string[] args)
            {
                string lordcheeto = @"\s*('.*?'|&&|==|<=|>=|<|>|\(|\)|\+|-|\|\|)\s*";
    
                string input = "Name=='mynme' && CurrentTime<45 - 4";
                string input1 = "Name=='mynme' && CurrentTime<'2012-04-20 19:45:45'";
                string input2 = "((1==2) && 2-1==1) || 3+1==4 && Name=='Stefan+123'";
    
                executePattern("lordcheeto's", input, lordcheeto);
                executePattern("lordcheeto's", input1, lordcheeto);
                executePattern("lordcheeto's", input2, lordcheeto);
    
                Console.ReadLine();
            }
    
            static void executePattern(string version, string input, string pattern)
            {
                // Avoiding repitition for this example.
                Console.WriteLine("Using {0} pattern:", version);
    
                // Needs to be trimmed.
                var result = Regex.Split(input.Trim(), pattern);
    
                // Pipe included to highlight empty strings.
                foreach (var m in result)
                    Console.WriteLine("|{0}", m);
    
                // Extra space.
                Console.WriteLine();
                Console.WriteLine();
            }
        }
    }
    

    Test:

    http://goo.gl/lkaoM

    Output:

    Using lordcheeto's pattern:
    |Name
    |==
    |
    |'mynme'
    |
    |&&
    |CurrentTime
    |<
    |45
    |-
    |4
    
    
    Using lordcheeto's pattern:
    |Name
    |==
    |
    |'mynme'
    |
    |&&
    |CurrentTime
    |<
    |
    |'2012-04-20 19:45:45'
    |
    
    
    Using lordcheeto's pattern:
    |
    |(
    |
    |(
    |1
    |==
    |2
    |)
    |
    |&&
    |2
    |-
    |1
    |==
    |1
    |)
    |
    |||
    |3
    |+
    |1
    |==
    |4
    |&&
    |Name
    |==
    |
    |'Stefan+123'
    |
    

    Additional Comments:

    If you want to split on any other operators (e.g., <<, +=,=, -=, >>) as well (there’s a lot), or need anything else, just ask.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.