D/正規表現

Top / D / 正規表現

マッチした位置の取得

RegExp re = new RegExp(`[0-9]+`,null);
char src[] = "2005/04/23";

for (bit isFirst=true; ; isFirst=false) {
	int result = isFirst ? re.test(src) : re.test();
	if (!result) break;

	int start = re.pmatch[0].rm_so;
	int end = re.pmatch[0].rm_eo;

	printf("%s: %d - %d\n", toStringz(src[start..end]), start, end);
}

publicではないpmatchを使う違法くさいコード。


トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2005-05-21 (土) 01:05:48 (6914d)