James Mathieson
James Mathieson

Reputation: 439

Check if number in string with regex

My regex knowledge is strictly limited, but I need to use it to check a string for a specific number, e.g.

12345 123543 123222 4124214 2323 42124 23123 24444 34342

How can I use regex to confirm whether 2323 is in the above string?

Basically, if the string contains the number, for my project, then the string and the number are a match. If this isn't clear, please let me know and I'll try to expand.

Upvotes: 2

Views: 143

Answers (1)

tckmn
tckmn

Reputation: 59273

The regex for checking if 2323 is in the string is:

.*\b2323\b.*

This means anything, then 2323, then anything. The \bs will make sure that the 2323 is not in the middle of a number, but its own number. (Without the \b word boundaries, the regex would match 83523238 because it has 2323 in it.)

Upvotes: 4

Related Questions