473,385 Members | 1,640 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Split line based on specific pattern using Regex

i need to split lines in text file based on a specific pattern.The pattern is " 01/12/12 00:39 AT400003".

The source file looks like:

AT400003 2012-12-01 00:36:03.000 abcdefghij 01/12/12 00:39 AT400003 abcdefjhij 01/12/12 01:39 AT400003 abcdefghij 01/12/12 00:39 AT400003 abcdefjhij

I need the output file to look like:

AT400003 2012-12-01 00:36:03.000 abcdefghij
01/12/12 00:39 AT400003 abcdefjhij
01/12/12 01:39 AT400003 abcdefghij
01/12/12 00:39 AT400003 abcdefjhij

But I get:

AT400003 2012-12-01 00:36:03.000 abcdefghij
abcdefjhij
abcdefghij
abcdefjhij

Below is the code:

string[] lines = System.Text.RegularExpressions.Regex.Split(keep, @"\s\s\s\d\d\/\d\d\/\d\d\s\d\d\:\d\d\s\s\w\w\d\d\d\d\d\d");
foreach (string line in lines)
{ sw.WriteLine(line); }
Please advise how i can have the split expressions also included
Jun 3 '14 #1
1 2094
I have solved this:added a positive look ahead to the expression.(?=...)
string[] lines = System.Text.RegularExpressions.Regex.Split(keep, @"(?=\s\s\s\d\d\/\d\d\/\d\d\s\d\d\:\d\d\s\s\w\w\d\d\d\d\d\d)");
foreach (string line in lines)
{ sw.WriteLine(line); }
Jun 3 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CV | last post by:
How can I match 'n' number of neighbouring words of a pattern using regular expressions? For example, suppose I am looking for the pattern "length xyz cm" in some text. where xyz is a number -...
0
by: Nakah | last post by:
Hi, I have to use Regex in order to parse Visual Basic 6 *.frm files. I need to get all controls. I have managed to get "normal" controls without problem, but I have some problem with controls...
16
by: Stephane | last post by:
Hi, I'm trying to replace parenthesis using Regex.replace but I'm always having this error: System.ArgumentException: parsing ":-)" - Too many )'s. Parameter name: :-) Here's my code: ...
4
by: dchan1 | last post by:
String line = " I am new to c# "; How to use Regex to split the string so that It would return a String array with: token = "I" token = "am" token = "new" token =...
4
by: Ya Ya | last post by:
Hi, I have a string with some fixed text and variable text. For example: "this is a fixed text THE NEEDED INFO more more fixed text". How do I get the the variable text (THE NEEDED INFO) from this...
3
by: =?Utf-8?B?aGVyYmVydA==?= | last post by:
I need to build an event-based asynchronous pattern (around a send/receive messaging API). Is there a step-by-step guidance about how to write code for the EBAP ? Does any book cover this theme...
3
by: kdsutaia | last post by:
Hi! I want to fetch "name" as per the name of the journal. <JOURNAL> name </JOURNAL> name will be diff in diff files. I am reading file line by line and sending pattern ...
0
by: rmeshksar | last post by:
Hi, I would like to do text replacement using RegEx and use the following statement: Regex.Replace(input, pattern, replacement, RegexOptions.IgnoreCase) It works fine in all cases except in the...
2
by: daveftl | last post by:
Hello, i've tried to extract certain data using Regex in a File. but it seems not working.No errors and warnings have been found. here is my code: Private Sub extractTxt(ByVal inputFile As...
1
by: jhosh | last post by:
I have a line say #abcd,19,19¬ name="efgh" label="ijkl"#mnop,22,28¬#qrst,23,25¬ name="uvwx"ƒ i have to split this line based on # but shouldn consider the first # .......the other # should be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.