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

Regular expression to extract the year (1900 - 2099) from a string

Getting year from text. If you want validate textbox value - use this pattern with "^" and "$": ^((19|20)\d{2})$

Tags: #date, #datetime, #extract, #parsing, #validate, #year. Views: 6438. admin, 3/28/2015
Link 1: http://www.systemtextregularexpressions.com/m2/regular-expression-to-extract-the-year-1900-2099-from-a-string
Link 2: http://www.systemtextregularexpressions.com/m2 (short)

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

RegexOptions

IsMatch=true


#ValueIndexLengthGroupsCaptures
01961864Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
119001584Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
219231644Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
319451704Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
419991764Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
520031824Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
620991884Skip Navigation Links.
Expand Groups [3]Groups [3]
Skip Navigation Links.
Expand Captures [1]Captures [1]
Count: 7, 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
0015
0016
//.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

//Namespace
using System.Text.RegularExpressions;

//Regex Pattern
string pattern = @"\b((19|20)\d{2})\b";

//Regex example #1
Regex r = new Regex(@"\b((19|20)\d{2})\b");
Match m1 = r.Match("input text");
MatchCollection mc1 = r.Matches("input text");

//Regex example #2
Match m2 = Regex.Match("input text", @"\b((19|20)\d{2})\b");
MatchCollection mc2 = Regex.Matches("input text", @"\b((19|20)\d{2})\b");
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
'.NET Regex.Match Online Tester: www.systemtextregularexpressions.com

'Namespace
Imports System.Text.RegularExpressions

'Regex Pattern
Dim pattern As String = "\b((19|20)\d{2})\b"

'Regex example #1
Dim r As Regex = New Regex("\b((19|20)\d{2})\b")
Dim m1 As Match = r.Match("input text")
Dim mc As MatchCollection = r.Matches("input text")

'Regex example #2
Dim m2 As Match = Regex.Match("input text", "\b((19|20)\d{2})\b")
Dim mc2 As MatchCollection = Regex.Matches("input text", "\b((19|20)\d{2})\b")

Home     Match     Replace     Split     Help     Library     Contacts     netregex rss

Made by Koshevoy Dmitry [8Bytes],

© 2014-2024 Ukraine, Nikolaev.