在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ 正則匹配的問題

正則匹配的問題

目標(biāo)字符串是:12.3....ed....6756....434dsfsd....
需要以....來分組,和用split分組字符串一樣,但是想用正則的方法進(jìn)行分組。
這個(gè)正則表達(dá)式該怎么寫呢?

回答
編輯回答
清夢(mèng)

.split(/.{4}/)

這樣分割產(chǎn)生的結(jié)果最后一個(gè)元素是空字符串

2018年4月21日 07:00
編輯回答
蔚藍(lán)色

/(.+)(?=\.{4})/

2018年9月21日 07:38
編輯回答
病癮

clipboard.png

<?php
$str = "12.3....ed....6756....434dsfsd....";
preg_match_all('/(.*?)\.\.\.\./',$str,$b);
print_r($b);
?>
輸出:
Array
(
    [0] => Array
        (
            [0] => 12.3....
            [1] => ed....
            [2] => 6756....
            [3] => 434dsfsd....
        )

    [1] => Array
        (
            [0] => 12.3
            [1] => ed
            [2] => 6756
            [3] => 434dsfsd
        )

)
2018年5月6日 15:24
編輯回答
擱淺

分組的個(gè)數(shù)應(yīng)該是確定的,沒發(fā)寫不確定個(gè)數(shù)的分組吧

2017年1月13日 11:43
編輯回答
爛人

正則我不熟,現(xiàn)學(xué)現(xiàn)賣...

這樣試一下?

.+?\.{4}

共找到 4 處匹配:
12.3....
ed....
6756....
434dsfsd....
2017年10月23日 13:05
編輯回答
懷中人

正則表達(dá)式: (\.{4})

        String[] attr = "12.3....ed....6756....434dsfsd....".split("(\\.{4})");
String string = "12.3....ed....6756....434dsfsd....";

Pattern pattern = Pattern.compile("(\\.{4})");
Matcher matcher = pattern.matcher(string);
System.out.println(matcher.matches());
int pre = 0;
//查找符合規(guī)則的子串
while (matcher.find()) {
    //獲取 字符串
    System.out.println(matcher.group());
    //獲取的字符串的首位置和末位置
    System.out.println(string.substring(pre, matcher.start()));
    pre = matcher.end();
}
2018年4月19日 09:52