Regular Expressions: Capturing the date


Using regular expressions, first detect the text; then capture the date according to the output.



Part A: Detects the text

\w: designates a string
\d: designates a number
\s: designates a whitespace

\w{1,3}: designates three characters.
\d{1,4}: designates a four numbers.
\s: designates a white space.

Merging: \w{1,3}\s\d{1,4}

That would detect the text perfectly but not capture what is demanded, look:

Part B: Captures the date

We have:


To capture what you want, simple add parentheses.

First the date:


Then the whole expression:


Now, you have to merge both:



Alternative solution:
(\w+ (\d+))

No comments :

Post a Comment

Follow Me

If you like our content, feel free to follow me to stay updated.


Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?


Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact