473,657 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegEx: Adding an "OR" condition to an existing expression

The following function, SplitTheString( ), splits a string based on a flag
that is like this:
{Flag1:whatever Here}
Note that the "whateverHe re" part can be any character - and at least one
character.

I simply want to extend this RegEx to do the same job - but to do it based
on an additional possible flag:
{Flag2:whatever Here}

So, the split would be based on {Flag1:whatever Here} OR {Flag2:whatever Here}
public static string[] SplitTheString( string inString) {
Regex r = new Regex("({Flag1: .+?})"); // Split on hyphens.
string[] sa = r.Split(inStrin g);
for(int i=0; i< sa.Length; i++) {
sa[i] = sa[i].Trim();
}
return sa;
}

Thanks to William Stacey for the initial version of this Split() function.

-GH
Nov 17 '05 #1
1 10185
Try using the vertical bar character which is equivalent to a logical OR:

Regex r = new Regex("({Flag1: \w+?}|{Flag2:\d +?})");

Try this reference for the future:

http://msdn.microsoft.com/library/de...geElements.asp

--
Dave Sexton
dave@www..jwaon line..com
-----------------------------------------------------------------------
"Guadala Harry" <GM**@NoSpam.ne t> wrote in message news:%2******** **********@TK2M SFTNGP14.phx.gb l...
The following function, SplitTheString( ), splits a string based on a flag that is like this:
{Flag1:whatever Here}
Note that the "whateverHe re" part can be any character - and at least one character.

I simply want to extend this RegEx to do the same job - but to do it based on an additional possible flag:
{Flag2:whatever Here}

So, the split would be based on {Flag1:whatever Here} OR {Flag2:whatever Here}
public static string[] SplitTheString( string inString) {
Regex r = new Regex("({Flag1: .+?})"); // Split on hyphens.
string[] sa = r.Split(inStrin g);
for(int i=0; i< sa.Length; i++) {
sa[i] = sa[i].Trim();
}
return sa;
}

Thanks to William Stacey for the initial version of this Split() function.

-GH

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

40
3021
by: Steve Juranich | last post by:
I know that this topic has the potential for blowing up in my face, but I can't help asking. I've been using Python since 1.5.1, so I'm not what you'd call a "n00b". I dutifully evangelize on the goodness of Python whenever I talk with fellow developers, but I always hit a snag when it comes to discussing the finer points of the execution model (specifically, exceptions). Without fail, when I start talking with some of the "old-timers"...
12
3222
by: junky_fellow | last post by:
Which is better using a switch statement or the if-then equivalent of switch ?
10
28626
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG means the code does not even reach the IL when compiling in release mode. Is there any benefit to using the Conditional Attribute? Am I right in thinking there will small performance overhead using over #if DEBUG.
2
2936
by: Julio Allegue | last post by:
I am getting the wrong Count(*) on vb.net using the ExecuteScalar . It returns all the rows. It doesn't seem to look at the WHERE clause. At the same time, I am getting the correct count on "SQL Enterprise Manager" or "SQL Query Analyser" using the same SQL statement. Thanks in advance. Julio. Here is the SQL statement plus the source to the GetNumOfRow sub.
1
2204
by: feng | last post by:
Hi, I know this might not be a question for this group but I would give it a try anyway as I couldn't find a better group for my question. I have noticed that there are a lot of articles out side of Microsoft's world that talk about the Rule-based design for business rules, or also known as "Event-condition- action" pattern.
4
4941
by: michael.bollhoefer | last post by:
I am trying to split a string into two different variables. The string is pulled from an XML file from a WEBDAV program. The string will be in this form "John Doe" <john.doe@webserver.com> the qoutes and <> are actually part of whole strinng. I need to be able to split the name into one variable and the e-mail address into another. I have been playing around with the .split but have not had much luck. Any suggestions?
2
4844
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance. I'm having trouble with something that I'm trying for the first time. Using Access 2000 - I want to run a function either on the click of a button or on leaving a text box. For the immediate task, either will work as well as the other. I think. I'm just at the beginning of this, and the form has two text boxes - Text0 and Text1. The user input to Text0 is a dollar amount, in...
37
3926
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as a function
6
1976
by: Russ P. | last post by:
I've always appreciated Python's lack of requirement for a semi-colon at the end of each line. I also appreciate its rules for automatic line continuation. If a statement ends with a "+", for example, Python recognizes that the statement obviously must continue. I've noticed, however, that the same rule does not apply when a line ends with "and," "or," or "not." Yes, it's a minor point, but shouldn't the same rule apply? Seems like it...
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4171
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.