<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>INSPIRE TECH &#187; regex</title>
	<atom:link href="http://inspire-tech.jp/tag/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://inspire-tech.jp</link>
	<description>株式会社インスパイアデザインのプログラマーである家富正幸が、デザインやシステム開発、ソーシャルメディアや最近のトレンドなど、Webに関する様々な情報を発信しているブログです。</description>
	<lastBuildDate>Fri, 29 Jan 2016 05:25:58 +0000</lastBuildDate>
	<language>ja</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.8.41</generator>
	<item>
		<title>printfのフォーマットから、変換指定子を抜き出す正規表現</title>
		<link>http://inspire-tech.jp/2010/12/regular_expression_that_searches_conversion_specifications_of_printf_function/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=regular_expression_that_searches_conversion_specifications_of_printf_function</link>
		<comments>http://inspire-tech.jp/2010/12/regular_expression_that_searches_conversion_specifications_of_printf_function/#comments</comments>
		<pubDate>Sat, 25 Dec 2010 14:34:41 +0000</pubDate>
		<dc:creator><![CDATA[家富 正幸]]></dc:creator>
				<category><![CDATA[その他]]></category>
		<category><![CDATA[参考]]></category>
		<category><![CDATA[開発]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://inspire-tech.jp/?p=265</guid>
		<description><![CDATA[そんなに用途は無いと思うんですが、PHPのpirntf構文やsprintf構文のフォーマットから変換指定子（%sや%d等）を抜き出す正規表現を書いてみました。 /(?:^&#124;[^%])%(?:[0-9]+\$)?(?:[\ [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>そんなに用途は無いと思うんですが、PHPのpirntf構文やsprintf構文のフォーマットから変換指定子（%sや%d等）を抜き出す正規表現を書いてみました。</p>
<pre class="brush: text">
/(?:^|[^%])%(?:[0-9]+\$)?(?:[\+\-]?(?:0|\'[^%])?[\d]*?(?:\.\d+)?)?[bcdeEufFgGosxX]/u
</pre>
<p>preg_match_allなどで利用すれば、変換指定子が何個使用されているかなどを調べることができると思います。</p>
<h3><span>用途</span></h3>
<p>プログラム中でprintf構文に必要とされる引数の数を調べなくてはならなくなり、下記のような関数を作って利用しています。</p>
<pre class="brush: php">
function _argAmount($pattern)
{
	preg_match_all(
		'/(?:^|[^%])%(?:([0-9]+)\$)?(?:[\+\-]?(?:0|\'[^%])?[\d]*?(?:\.\d+)?)?[bcdeEufFgGosxX]/',
		$pattern,
		$matches
	);

	$count = 0;

	if (!empty($matches[1])) {
		$filtered = array_filter($matches[1]);
		$max = max($filtered);
		$empty = count($matches[1]) - count($filtered);
		$count = ($max > $empty) ? $max : $empty;
	}

	return $count;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://inspire-tech.jp/2010/12/regular_expression_that_searches_conversion_specifications_of_printf_function/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
	</channel>
</rss>
