Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression - Finding 4 digits in a string

Tags:

string

c#

regex

I was wondering if anyone could help me out with finding a simple regular expression to search through a string and find and pull out 4 digits with no whitespace between.

For example, I am trying to find a year in a string such as 1965. If the string said "30 Jan 1965" and I wanted to pull out "1965", how would I go about it?

I have found others on the internet but I just get an empty set returned. Thank you

like image 589
user1290653 Avatar asked Dec 07 '22 14:12

user1290653


1 Answers

The regex \b\d{4}\b will do the trick.

like image 89
Prince John Wesley Avatar answered Dec 22 '22 01:12

Prince John Wesley