Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to extract words that contain digits

Tags:

c#

regex

I need to extract words that contain digits.

ex:-

Input - 3909B Witmer Road. Niagara Falls. NY 14305

Output - 3909B and 14305

like image 485
Dan Avatar asked Jan 26 '12 04:01

Dan


People also ask

How do you match a regular expression with digits?

To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.

How do you check if a string is a number regex?

To check if a string contains only numbers in JavaScript, call the test() method on this regular expression: ^\d+$ . The test() method will return true if the string contains only numbers. Otherwise, it will return false . The RegExp test() method searches for a match between a regular expression and a string.

How do you get all the numbers in a string?

To get the list of all numbers in a String, use the regular expression '[0-9]+' with re. findall() method. [0-9] represents a regular expression to match a single digit in the string. [0-9]+ represents continuous digit sequences of any length.

How do you find all the numbers in a string python?

To find numbers from a given string in Python we can easily apply the isdigit() method. In Python the isdigit() method returns True if all the digit characters contain in the input string and this function extracts the digits from the string.


1 Answers

Use this regex:

\w*\d\w*

See it here in action: http://regexr.com?2vqui

like image 143
Joseph Silber Avatar answered Sep 20 '22 20:09

Joseph Silber