x Did you like it? Well, then please consider making a donation :)

Split string to get Date and text

I have to process text file like that: text 01/01/1970 text 02/01/1970 ... etc. I want the output to be the following data: according to the docs, wrapping the string you're splitting on in () (making it a capture group) will result in these captures being included in the array.

Tags: #date, #datetime, #example, #parsing, #regex.split, #sample, #split, #text. Views: 8876. stackoverflow, 8/12/2015
Link 1: http://www.systemtextregularexpressions.com/s18/split-string-to-get-date-and-text
Link 2: http://www.systemtextregularexpressions.com/s18 (short)

Length: 0b, Line: 1, Cursor: 0

RegexOptions

IsMatch=true


#Value
0first date:
107/14/2007
2 second date:
302/13/2005
4 third date:
506/12/1984
6 regex date split example:
701/01/1970
8 yeap!
Count: 9, Time: 00:00:00

Share (without adding to database):

Source code

0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
//.NET Regex.Split Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"(\d{1,2}/\d{1,2}/\d{2,4})";

//Regex example #1
Regex r = new Regex(@"(\d{1,2}/\d{1,2}/\d{2,4})");
string[] result1 = r.Split("input text");

//Regex example #2
string[] result2 = Regex.Split("input text", @"(\d{1,2}/\d{1,2}/\d{2,4})");
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
'.NET Regex.Split Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "(\d{1,2}/\d{1,2}/\d{2,4})"

'Regex example #1
Dim r As Regex = New Regex("(\d{1,2}/\d{1,2}/\d{2,4})")
Dim result1() As String = r.Split("input text")

'Regex example #2
Dim result2() As String = Regex.Split("input text", "(\d{1,2}/\d{1,2}/\d{2,4})")

Home     Match     Replace     Split     Help     Library     Contacts     netregex rss

Made by Koshevoy Dmitry [8Bytes],

© 2014-2024 Ukraine, Nikolaev.