Re: [問題] 怎麼取得/ 之間的字串
看板RegExp (正規表示式 Regular Expression)作者godspeedlee (我是好人,也是個壞人)時間13年前 (2011/06/25 17:00)推噓1(1推 0噓 60→)留言61則, 3人參與討論串2/2 (看更多)
※ 引述《knives ()》之銘言:
: 我有一個字串
: http://www.tudou.com/programs/view/Bic3TWWQrRY/
: 我想要取得最後一個Bic3TWWQrRY
: 我的想法是 /\/[\w+]*\//
: 可是最後會取到/Bic3TWWQrRY/
: 要怎麼把左右兩個/拿掉阿
: 謝謝回答
用 RegexBuddy 測試過 ok
http://\w+(?:\.[-\w]+)*/(?:\w+/)+(\w+)/
稍微說明一下:
前面兩個 (?:...) 是告訴 regex engine 這只是分組用的,
不需要儲存(capture),真正會儲存的只有最後一個括號。
第二個 (?:...) 會一路把所有的 path 吃完,但是因為碰到
(\w+)/ 所以會逐步交還字元直到比對成功
這個 pattern 是隨手寫的,辨識 url 的範例很多,不想
花時間研究就去抄 Regular Expression Cookbook 就好了
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.124.102.177
→
06/25 22:28, , 1F
06/25 22:28, 1F
→
06/25 22:40, , 2F
06/25 22:40, 2F
→
06/26 00:07, , 3F
06/26 00:07, 3F
→
06/26 00:08, , 4F
06/26 00:08, 4F
→
06/26 06:16, , 5F
06/26 06:16, 5F
→
06/26 06:17, , 6F
06/26 06:17, 6F
→
06/26 06:24, , 7F
06/26 06:24, 7F
→
06/26 06:26, , 8F
06/26 06:26, 8F
→
06/26 06:44, , 9F
06/26 06:44, 9F
→
06/26 06:47, , 10F
06/26 06:47, 10F
→
06/26 06:50, , 11F
06/26 06:50, 11F
→
06/26 06:52, , 12F
06/26 06:52, 12F
→
06/26 15:04, , 13F
06/26 15:04, 13F
→
06/26 15:05, , 14F
06/26 15:05, 14F
→
06/26 15:09, , 15F
06/26 15:09, 15F
→
06/26 15:35, , 16F
06/26 15:35, 16F
→
06/26 15:35, , 17F
06/26 15:35, 17F
→
06/26 15:35, , 18F
06/26 15:35, 18F
→
06/26 15:35, , 19F
06/26 15:35, 19F
→
06/26 15:36, , 20F
06/26 15:36, 20F
→
06/26 15:36, , 21F
06/26 15:36, 21F
→
06/26 15:36, , 22F
06/26 15:36, 22F
→
06/26 15:40, , 23F
06/26 15:40, 23F
→
06/26 15:42, , 24F
06/26 15:42, 24F
→
06/26 15:43, , 25F
06/26 15:43, 25F
→
06/26 15:53, , 26F
06/26 15:53, 26F
→
06/26 15:53, , 27F
06/26 15:53, 27F
→
06/26 15:54, , 28F
06/26 15:54, 28F
→
06/26 15:54, , 29F
06/26 15:54, 29F
→
06/26 16:01, , 30F
06/26 16:01, 30F
→
06/26 16:05, , 31F
06/26 16:05, 31F
→
06/26 16:05, , 32F
06/26 16:05, 32F
→
06/26 16:06, , 33F
06/26 16:06, 33F
→
06/26 16:06, , 34F
06/26 16:06, 34F
→
06/27 00:46, , 35F
06/27 00:46, 35F
→
06/27 00:47, , 36F
06/27 00:47, 36F
→
06/27 00:47, , 37F
06/27 00:47, 37F
→
06/27 00:47, , 38F
06/27 00:47, 38F
→
06/27 08:55, , 39F
06/27 08:55, 39F
→
06/27 08:55, , 40F
06/27 08:55, 40F
→
06/27 09:06, , 41F
06/27 09:06, 41F
→
06/27 09:06, , 42F
06/27 09:06, 42F
→
06/27 09:07, , 43F
06/27 09:07, 43F
→
06/27 09:07, , 44F
06/27 09:07, 44F
→
06/27 09:07, , 45F
06/27 09:07, 45F
→
06/27 09:07, , 46F
06/27 09:07, 46F
→
06/27 09:07, , 47F
06/27 09:07, 47F
→
06/28 01:00, , 48F
06/28 01:00, 48F
→
06/28 01:01, , 49F
06/28 01:01, 49F
→
06/28 01:02, , 50F
06/28 01:02, 50F
→
06/28 01:04, , 51F
06/28 01:04, 51F
※ 編輯: godspeedlee 來自: 122.124.100.96 (06/28 01:12)
→
06/28 08:37, , 52F
06/28 08:37, 52F
→
06/28 08:37, , 53F
06/28 08:37, 53F
→
06/28 08:38, , 54F
06/28 08:38, 54F
→
06/28 08:39, , 55F
06/28 08:39, 55F
→
06/28 08:41, , 56F
06/28 08:41, 56F
→
06/28 08:43, , 57F
06/28 08:43, 57F
→
06/28 08:47, , 58F
06/28 08:47, 58F
→
06/28 08:49, , 59F
06/28 08:49, 59F
→
06/28 08:50, , 60F
06/28 08:50, 60F
推
06/28 22:57, , 61F
06/28 22:57, 61F
討論串 (同標題文章)
RegExp 近期熱門文章
PTT數位生活區 即時熱門文章