Regexp for date [duplicate]

I have a lot of LOC of a project in visual studio and I want to search for every line which uses the numbers 12 and 13. It can't be part of a bigger number, I need to retrieve only the code that actually uses the constants 12 and 13. I think it is possible to do with regex but I'm having a hard time here.

Any help will be very appreciated.


Brief

You want to use the Find and Replace window found at Edit -> Find and Replace -> Find in Files with the regex \b1[23]\b and the Find Options Use Regular Expressions checkbox selected.

Find and Replace box


Code

  • \b Word boundary assertion
    • Matches, without consuming any characters, immediately between a character matched by \w and a character not matched by \w (in either order). It cannot be used to separate non-words from words.
  • 1 Match this literally
  • [23] Match a character in the set (2 or 3)
  • \b Word boundary assertion

(?<![0-9])1[23](?![0-9])

Will match

12
13
abc12hbd

but not

3456324123656
234564567546
121212
13121312
1
3
123

If your 12 or 13 might appear in a hexadecimal string you can exclude that with

(?<![0-9a-fA-F])1[23](?![0-9a-fA-F])

You need to decide what characters are allowed to be on either side of the 12 or 13 and then exclude the others. See https://regex101.com/ for more help