F**e 发帖数: 593 | 1 需要把数字rewrite: 首先把每个数字left pad 0成8位
1 -> 00000001
123456 -> 00123456
然后每三位加/
1 -> 00000001 -> 00/000/001
123456 -> 00123456 -> 00/123/456
12345678 -> 12345678 -> 123/456/789
包子答谢! |
t*****g 发帖数: 1275 | 2 第一步padding不好作吧。
实在不行试试写8个rewriterule,对不同宽度的input?比如
...
^(\d)(\d{3})$ /00/00$1/$2
^(\d\d)(\d{3})$ /00/0$1/$2
...
【在 F**e 的大作中提到】 : 需要把数字rewrite: 首先把每个数字left pad 0成8位 : 1 -> 00000001 : 123456 -> 00123456 : 然后每三位加/ : 1 -> 00000001 -> 00/000/001 : 123456 -> 00123456 -> 00/123/456 : 12345678 -> 12345678 -> 123/456/789 : 包子答谢!
|
r*******n 发帖数: 3020 | 3 简单起见,假设你的数字都每行的开头,
并以数字结尾,如果不是你可以很容易处理成这个样子。
我用vim,其他类似。
分三步:
1 每个数字前加8个0
:%s/^/00000000/g
2 取后8个数
:%s/0\+\(\d\{8}\)$/\1/g
3 加/
:%s/\(\d\{2}\)\(\d\{3}\)/\1\/\2\//g
【在 F**e 的大作中提到】 : 需要把数字rewrite: 首先把每个数字left pad 0成8位 : 1 -> 00000001 : 123456 -> 00123456 : 然后每三位加/ : 1 -> 00000001 -> 00/000/001 : 123456 -> 00123456 -> 00/123/456 : 12345678 -> 12345678 -> 123/456/789 : 包子答谢!
|
m******t 发帖数: 2416 | 4
If you want to go fancy, in apache 2, you can use
RewriteMap to send a url to an external script
and rewrite it there however you want.
I would go with the 8-rule approach somebody else
suggested though. It's straightforward enough.
【在 F**e 的大作中提到】 : 需要把数字rewrite: 首先把每个数字left pad 0成8位 : 1 -> 00000001 : 123456 -> 00123456 : 然后每三位加/ : 1 -> 00000001 -> 00/000/001 : 123456 -> 00123456 -> 00/123/456 : 12345678 -> 12345678 -> 123/456/789 : 包子答谢!
|
F**e 发帖数: 593 | 5 包子已发。谢谢。
我现在就用8 rules了。
还有个基本问题,怎么group with some optional string? The problem is I have
either NNN or NNN.jpg
for example
123
123.jpg
how do I have one single group (last group) that matches both these two
patterns? I tried this:
([0-9]{3}[\.jpg]?)
doesn't work.
THanks a lot!
【在 m******t 的大作中提到】 : : If you want to go fancy, in apache 2, you can use : RewriteMap to send a url to an external script : and rewrite it there however you want. : I would go with the 8-rule approach somebody else : suggested though. It's straightforward enough.
|
t*****g 发帖数: 1275 | 6 (\d{3})(\.jpg)?
$1 holds the NNN you need.
【在 F**e 的大作中提到】 : 包子已发。谢谢。 : 我现在就用8 rules了。 : 还有个基本问题,怎么group with some optional string? The problem is I have : either NNN or NNN.jpg : for example : 123 : 123.jpg : how do I have one single group (last group) that matches both these two : patterns? I tried this: : ([0-9]{3}[\.jpg]?)
|
F**e 发帖数: 593 | 7 never mind, I figured out. I can just use $1$2 as the whole thing. thanks!! 接新包子 :) |
t*****g 发帖数: 1275 | 8 (\d{3}(\.jpg)?)
$1 holds the whole part
have
【在 F**e 的大作中提到】 : never mind, I figured out. I can just use $1$2 as the whole thing. thanks!! 接新包子 :)
|
F**e 发帖数: 593 | 9 ha, even better!
【在 t*****g 的大作中提到】 : (\d{3}(\.jpg)?) : $1 holds the whole part : : have
|
t*****g 发帖数: 1275 | 10 包子收到,吱一声
! 接新包子 :)
have
【在 F**e 的大作中提到】 : never mind, I figured out. I can just use $1$2 as the whole thing. thanks!! 接新包子 :)
|