sotn
sotn

Reputation: 2101

Notepad++ regex for unix epoch timestamp

I have a text file that has unix epoch timestamps mixed in with a lot of scrambled text. So, I need to check for 10 digit numbers, starting and ending with non-numeric characters.

I tried:

[:alpha:]([0-9]{10})[:alpha:]

but it doesn't work.

Upvotes: 1

Views: 2002

Answers (2)

Peter Thoeny
Peter Thoeny

Reputation: 7616

I just tested this text with notepad++:

aaa1234567890bbb
11.1234567890@99
too short:123456789
  • search: (?<=\D)(\d{10})(?=\D)
  • replace: (whatever you want; use $1 for captured number)

Explanation:

  • (?<=\D) - positive lookbehind for a non-digit char (no capture)
  • (\d{10}) - capture 10 digits
  • (?=\D) - positive lookahead for a non-digit char (no capture)

Upvotes: 1

bw_&#252;ezi
bw_&#252;ezi

Reputation: 4564

Maybe the POSIX [:alpha:] doesn't work with Notepad++

[:alpha:] equals [a-zA-Z] and in your case may also be substituted by \D (equals One non-digit)

Have you tried one of these:
(fist will select 10 digits including 2 extra characters at start/end
others with lookahead/lookbehind just select the exact 10 digits)

  • \D([0-9]{10})\D
  • (?<=\D)([0-9]{10})(?=\D) positive lookahead/lookbehind
  • (?<!\d)([0-9]{10})(?!\d) negative lookahead/lookbehind

Upvotes: 1

Related Questions