目标字符串是:12.3....ed....6756....434dsfsd....
需要以....
来分组,和用split分组字符串一样,但是想用正则的方法进行分组。
这个正则表达式该怎么写呢?
目标字符串是:12.3....ed....6756....434dsfsd....
需要以....
来分组,和用split分组字符串一样,但是想用正则的方法进行分组。
这个正则表达式该怎么写呢?
正则表达式: (\.{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;
//查找符合规则的子串
while (matcher.find()) {
//获取 字符串
System.out.println(matcher.group());
//获取的字符串的首位置和末位置
System.out.println(string.substring(pre, matcher.start()));
pre = matcher.end();
}
<?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
)
)
正则我不熟,现学现卖...
这样试一下?