473,785 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return Data Regex Doesn't Isolate - Yikes

Folks,

I'm having a bad regex day and can sure use your help, please..

I have a Regex expression that works fine. It's purpose is to isolate all
data from the start of a string begining with 200~ to the end of the string
but before the start of the next 200~. Here's the regex expression and test
data:

(?ms)^200~(.*?) (?=^200~)

Here's some test data

000000000000000 00000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888

The regex will return 200~ plus all ones, twos, threes as a group then 200~
plus all fours, fives, sixes as a group

Problem
---------
Now I need to do the reverse. I need to return all the data the preceding
regex doesn't return. IOW, I need to return all the zeros and 200~ plus all
the sevens and all the eights as a group. I want to execute "NOT
(?ms)^200~(.*?) (?=^200~)"

Sure could use a pointer to the correct starting point or any suggestion
that will help me reach my goal.

Thanks in advance

ty_92648 AT hotmail.com
Nov 16 '05 #1
4 1864
I had some rather large explanation of how to do it procedurally, but then I
thought,
"Justin, get off your arse and write some regular expression magic!". So here
you go.

using System;
using System.Text.Reg ularExpressions ;

public class SuperRegex {
private static string stuff =
@"0000000000000 0000000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888";

private static void Main(string[] args) {
Regex regex = new Regex("(?ms)(?: \\A|^200~)(.*?) (?=^200~|\\Z)") ;
MatchCollection matches = regex.Matches(s tuff);
for(int i = 0; i < matches.Count; i++) {
Console.WriteLi ne();
Console.WriteLi ne(matches[i].Value);
Console.WriteLi ne();
}
}
}
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Garibaldi" <ty_92648 AT hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Folks,

I'm having a bad regex day and can sure use your help, please..

I have a Regex expression that works fine. It's purpose is to isolate all
data from the start of a string begining with 200~ to the end of the string
but before the start of the next 200~. Here's the regex expression and test
data:

(?ms)^200~(.*?) (?=^200~)

Here's some test data

000000000000000 00000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888

The regex will return 200~ plus all ones, twos, threes as a group then 200~
plus all fours, fives, sixes as a group

Problem
---------
Now I need to do the reverse. I need to return all the data the preceding
regex doesn't return. IOW, I need to return all the zeros and 200~ plus all
the sevens and all the eights as a group. I want to execute "NOT
(?ms)^200~(.*?) (?=^200~)"

Sure could use a pointer to the correct starting point or any suggestion
that will help me reach my goal.

Thanks in advance

ty_92648 AT hotmail.com

Nov 16 '05 #2

You could just call Regex.Replace with the same expression and an empty
string as the replacement if you didn't need to access any of the match
properties (index, groups, etc.).

Brian Davis
http://www.knowdotnet.com

"Garibaldi" <ty_92648 AT hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Folks,

I'm having a bad regex day and can sure use your help, please..

I have a Regex expression that works fine. It's purpose is to isolate all
data from the start of a string begining with 200~ to the end of the string but before the start of the next 200~. Here's the regex expression and test data:

(?ms)^200~(.*?) (?=^200~)

Here's some test data

000000000000000 00000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888

The regex will return 200~ plus all ones, twos, threes as a group then 200~ plus all fours, fives, sixes as a group

Problem
---------
Now I need to do the reverse. I need to return all the data the preceding
regex doesn't return. IOW, I need to return all the zeros and 200~ plus all the sevens and all the eights as a group. I want to execute "NOT
(?ms)^200~(.*?) (?=^200~)"

Sure could use a pointer to the correct starting point or any suggestion
that will help me reach my goal.

Thanks in advance

ty_92648 AT hotmail.com

Nov 16 '05 #3
Thanks, Brian. Appreciate your suggestion. I'll give a shot.
"Brian Davis" <br***@knowdotn et.nospam.com> wrote in message
news:OP******** ******@tk2msftn gp13.phx.gbl...

You could just call Regex.Replace with the same expression and an empty
string as the replacement if you didn't need to access any of the match
properties (index, groups, etc.).

Brian Davis
http://www.knowdotnet.com

"Garibaldi" <ty_92648 AT hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Folks,

I'm having a bad regex day and can sure use your help, please..

I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with 200~ to the end of the

string
but before the start of the next 200~. Here's the regex expression and

test
data:

(?ms)^200~(.*?) (?=^200~)

Here's some test data

000000000000000 00000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888

The regex will return 200~ plus all ones, twos, threes as a group then

200~
plus all fours, fives, sixes as a group

Problem
---------
Now I need to do the reverse. I need to return all the data the preceding regex doesn't return. IOW, I need to return all the zeros and 200~ plus

all
the sevens and all the eights as a group. I want to execute "NOT
(?ms)^200~(.*?) (?=^200~)"

Sure could use a pointer to the correct starting point or any suggestion
that will help me reach my goal.

Thanks in advance

ty_92648 AT hotmail.com


Nov 16 '05 #4
Got it, thanks, Justin!

"Justin Rogers" <Ju****@games4d otnet.com> wrote in message
news:O8******** ******@TK2MSFTN GP12.phx.gbl...
I had some rather large explanation of how to do it procedurally, but then I thought,
"Justin, get off your arse and write some regular expression magic!". So here you go.

using System;
using System.Text.Reg ularExpressions ;

public class SuperRegex {
private static string stuff =
@"0000000000000 0000000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888";

private static void Main(string[] args) {
Regex regex = new Regex("(?ms)(?: \\A|^200~)(.*?) (?=^200~|\\Z)") ;
MatchCollection matches = regex.Matches(s tuff);
for(int i = 0; i < matches.Count; i++) {
Console.WriteLi ne();
Console.WriteLi ne(matches[i].Value);
Console.WriteLi ne();
}
}
}
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Garibaldi" <ty_92648 AT hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Folks,

I'm having a bad regex day and can sure use your help, please..

I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with 200~ to the end of the string but before the start of the next 200~. Here's the regex expression and test data:

(?ms)^200~(.*?) (?=^200~)

Here's some test data

000000000000000 00000
200~11111111111 111111
222222222222222 22222222222222
3333333333333
200~44444444444 4444444444444
555555555555555 555555555555555 555
66666666
200~77777777777 7777777
888888888888

The regex will return 200~ plus all ones, twos, threes as a group then 200~ plus all fours, fives, sixes as a group

Problem
---------
Now I need to do the reverse. I need to return all the data the preceding regex doesn't return. IOW, I need to return all the zeros and 200~ plus all the sevens and all the eights as a group. I want to execute "NOT
(?ms)^200~(.*?) (?=^200~)"

Sure could use a pointer to the correct starting point or any suggestion
that will help me reach my goal.

Thanks in advance

ty_92648 AT hotmail.com


Nov 16 '05 #5

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

Similar topics

7
3127
by: Victor Hannak | last post by:
I have a class with the following public function: float FuncClass::GetResult() { try { return(Result); } catch (...) { WriteString("FuncClass::GetResult ERROR: Exception encountered"); return(0); } }
3
6511
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the criteria, the Mid function returns the values when I run the query. So if one of the values is a "t" (no quotes), can I not ask to isolate that record by putting "t" as a criteria? Nope - error, error. If I put it within the expression itself...
4
4381
by: Demetri | last post by:
Lets pretend you have a string array and each element is a sentence. Two of those elements read as follows: 1. The fox escaped from the hound. 2. The fox almost escaped. Now lets say you loop the string array and inside that loop you use a Regex class to determine if the current element matches a certain criteria. The criteria being as follows:
9
2819
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the code so I only have the documentation. I'm trying to call a function called z4date that, according to the docs, returns the date as "an 8-byte character string in the "YYYYMMDD" format". When I run it with this code I've written , I get "Can not...
4
305
by: Garibaldi | last post by:
Folks, I'm having a bad regex day and can sure use your help, please.. I have a Regex expression that works fine. It's purpose is to isolate all data from the start of a string begining with 200~ to the end of the string but before the start of the next 200~. Here's the regex expression and test data: (?ms)^200~(.*?)(?=^200~)
3
2154
by: Paula | last post by:
Hi !! What regular expression should I write to get data from an html tag? Example: <title> The data I want to retrieve </title> I want to get "The data I want to retrieve" Could be right this one? @<\s* (title)\s* > + (</title>)+
1
1746
by: howard dierking | last post by:
Hi all, I'm having a problem with a reg ex. Essentiall, I'm trying to isolate variable declarations from old vbscript where there was no explicit declaration requirement. This should seem easy enough - just identify by the assignment statement; except for the fact that vb uses a single '=' token for comparison as well as assignment. Therefore, I need a regex that will match assignment statements while excluding if statements. I...
5
2426
by: Kofi | last post by:
Any takers? Got a string of DNA as an input sequence GGATGGATG, apply the simple regex "GGATG" as in Regex r = new Regex("GGATG", (RegexOptions.Compiled)); MatchCollection matches = r.Matches("GGATGGATG"); Now I would expect to get two matches right? One at index 0 in the
2
3582
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information from the database and allow the user to update the database using the web page' stage and realized...
0
9646
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
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7504
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
6742
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
5386
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...
1
4055
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
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.