Ms7 Search
Google 搜尋 翻譯
calendar
« 十一月 2024 »
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
近期文章
文章分類
網站連結
Syndicate

« | »

javascript 用 regex 取出所要字串

2017-01-23 @ 19:10 in PHP, JavaScript, Sql

字串 abcd[0102] 想取出 0102

  1. 方法一:用 substr        var rc = "abcd[0102]".substr(5,4);
  2. 方法二:用 regex         var arr_rc = /^.*\[(\d+)\].*/.exec("abcd[0102]");        //取出符合我字串,第一個本身,第二個(),陣列從 0 開始
                                  var rc = arr_rc[1];
方法一固定從第六位取四位,0為第一位

方法二利用 partten 取出 [] 內的數字,不管前面有幾位都可以

迴響

javascript 用 regex 取出所要字串 | 豬窩

Today, I went to the beachfront with my children. I found a sea shell and gave it to my
4 year old daughter and said "You can hear the ocean if you put this to your ear." She placed
the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this
is entirely off topic but I had to tell someone!

作者 best hosting @ 21:07, 2020-08-05

javascript 用 regex 取出所要字串 | 豬窩

I’m not that much of a internet reader to be honest but your blogs
really nice, keep it up! I'll go ahead and bookmark your website to come back down the road.
Many thanks

作者 web host @ 02:55, 2020-08-06

javascript 用 regex 取出所要字串 | 豬窩

Spot on with this write-up, I honestly think this site needs a great deal more attention. I'll
probably be back again to read through more, thanks for the information!

作者 hosting services @ 09:42, 2020-08-14
«上一篇   1 2 3 4
發表迴響
 authimage