/get-regexp-between-timestamp

Algorithm for transform timestamp range to Regular Expression or Wildcard Symbol.

Primary LanguageGoMIT LicenseMIT

get-regexp-between-timestamp

Algorithm for transform timestamp range to Regular Expression or Wildcard Symbol.

1. Run Script

go run get_regexp_between_timestamp.go

examples:

StartTime = 1546300800 EndTime = 1570675775

Wildcard Symbol (can be use in redis selector if you don't know how to use lua script)

154630080[0123456789]
15463008[123456789][0123456789]
1546300[9][0123456789][0123456789]
154630[123456789][0123456789][0123456789][0123456789]
15463[123456789][0123456789][0123456789][0123456789][0123456789]
1546[456789][0123456789][0123456789][0123456789][0123456789][0123456789]
154[789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]
15[56][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]
1570[012345][0123456789][0123456789][0123456789][0123456789][0123456789]
15706[0123456][0123456789][0123456789][0123456789][0123456789]
157067[01234][0123456789][0123456789][0123456789]
1570675[0123456][0123456789][0123456789]
15706757[0123456][0123456789]
157067577[012345]

Regular Expression

154630080[0-9]
15463008[1-9][0-9]
1546300[9-9][0-9][0-9]
154630[1-9][0-9][0-9][0-9]
15463[1-9][0-9][0-9][0-9][0-9]
1546[4-9][0-9][0-9][0-9][0-9][0-9]
154[7-9][0-9][0-9][0-9][0-9][0-9][0-9]
15[5-6][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
1570[0-5][0-9][0-9][0-9][0-9][0-9]
15706[0-6][0-9][0-9][0-9][0-9]
157067[0-4][0-9][0-9][0-9]
1570675[0-6][0-9][0-9]
15706757[0-6][0-9]
157067577[0-5]

2. Choose Type

If GetBetweenString have the style params, then it can return regexp. For example:

GetBetweenString("0", "9")   // return [0123456789]
GetBetweenString("0", "9", "-")  // return [0-9]

It return a list, you can use list.join("|") to get regex.

get-regexp-between-timestamp

一个可以将时间戳字符串范围转换为正则或通配符的算法

1. 运行脚本

go run get_regexp_between_timestamp.go

例子:

StartTime = 1546300800 EndTime = 1570675775

通配符 (如果你不知道怎么使用lua脚本的话,可以用于redis的匹配)

154630080[0123456789]
15463008[123456789][0123456789]
1546300[9][0123456789][0123456789]
154630[123456789][0123456789][0123456789][0123456789]
15463[123456789][0123456789][0123456789][0123456789][0123456789]
1546[456789][0123456789][0123456789][0123456789][0123456789][0123456789]
154[789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]
15[56][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]
1570[012345][0123456789][0123456789][0123456789][0123456789][0123456789]
15706[0123456][0123456789][0123456789][0123456789][0123456789]
157067[01234][0123456789][0123456789][0123456789]
1570675[0123456][0123456789][0123456789]
15706757[0123456][0123456789]
157067577[012345]

正则表达式

154630080[0-9]
15463008[1-9][0-9]
1546300[9-9][0-9][0-9]
154630[1-9][0-9][0-9][0-9]
15463[1-9][0-9][0-9][0-9][0-9]
1546[4-9][0-9][0-9][0-9][0-9][0-9]
154[7-9][0-9][0-9][0-9][0-9][0-9][0-9]
15[5-6][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
1570[0-5][0-9][0-9][0-9][0-9][0-9]
15706[0-6][0-9][0-9][0-9][0-9]
157067[0-4][0-9][0-9][0-9]
1570675[0-6][0-9][0-9]
15706757[0-6][0-9]
157067577[0-5]

2. 选择正则还是通配符

在GetBetweenString中传第三个参数间隔符,如果传-则是正则,不传则是通配符。例如:

GetBetweenString("0", "9")   // return [0123456789]
GetBetweenString("0", "9", "-")  // return [0-9]

返回的是一个list,如果需要整合正则可以list.join("|")