당신이 특정 문자가 캡처 그룹 내에서 발생하지 않습니다 알고 있다면, 당신은 그룹 사이의 문자로 교체 한 후 예를 들어 XQuery를 1
에에 토큰 화 사용할 수 있습니다
tokenize(replace("abc1234", "(.+)(\d+)", "$1-$2"), "-")
당신은 사용하여 기능이 일반화 할 수
tokenize(replace("abc1234", "^.*?(.+?)(\d+).*?$", "$1-$2"), "-")
페이지로 교체 만들 문자열을 조인 : 그룹 이전과 이후/
확인하려면 대체 모든 것을 제거 같은 attern "$ 1 $ 2 $ 3 $ 4"모든 구분을 위해 : 당신이 분리기를 직접 지정하지 않으려면
declare function local:get-matches($input, $regex, $separator, $groupcount) {
tokenize(replace($input, concat("^.*?", $regex, ".*?$"), string-join(for $i in 1 to $groupcount return concat("$", $i), $separator)), $separator, "q")
};
local:get-matches("abc1234", "(.+?)(\d+)", "|", 2)
, 당신은 하나를 찾을 수있는 기능이 필요합니다. 입력 문자열보다 긴 모든 문자열은 캡처 그룹에서 발생할 수 없으므로 더 긴 구분자를 사용하여 항상 찾을 수 있습니다.
declare function local:get-matches($input, $regex, $separator) {
if (contains($input, $separator)) then local:get-matches($input, $regex, concat($separator, $separator))
else
let $groupcount := count(string-to-codepoints($regex)[. = 40])
return tokenize(replace($input, concat("^.*?", $regex, ".*?$"), string-join(for $i in 1 to $groupcount return concat("$", $i), $separator)), $separator, "q")
};
declare function local:get-matches($input, $regex) {
local:get-matches($input, $regex, "|#☎")
};
local:get-matches("abc1234", "(.+?)(\d+)")