<?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>PHPKuh.de &#187; sonstiges</title>
	<atom:link href="http://phpkuh.de/kategorie/sonstiges/feed/" rel="self" type="application/rss+xml" />
	<link>http://phpkuh.de</link>
	<description>Just a man, a computer and his PHP</description>
	<lastBuildDate>Thu, 01 May 2008 23:18:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Regular Expression (RegExp) aus String in JavaScript (JS)</title>
		<link>http://phpkuh.de/regexp-aus-string-javascript/</link>
		<comments>http://phpkuh.de/regexp-aus-string-javascript/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 08:36:39 +0000</pubDate>
		<dc:creator>Chefkoch</dc:creator>
				<category><![CDATA[sonstiges]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JS]]></category>
		<category><![CDATA[regexp]]></category>

		<guid isPermaLink="false">http://phpkuh.de/regexp-aus-string-javascript/</guid>
		<description><![CDATA[In PHP hatte ich in der t&#228;glichen Arbeit schon oft mit regul&#228;ren Ausdr&#252;cken (auch Regular Expressions oder kurz RegExp genannt) zu tun, in JavaScript habe ich damit bisher nur selten gearbeitet. F&#252;r ein aktuelles Projekt musste ich aber aus einem Array von Strings die regul&#228;ren Ausdr&#252;cke erzeugen und hatte einige Zeit damit zu tun, herauszufinden [...]]]></description>
			<content:encoded><![CDATA[<p>In PHP hatte ich in der t&#228;glichen Arbeit schon oft mit <a href="http://de.php.net/manual/en/reference.pcre.pattern.syntax.php" title="Erl&#228;uterungen zur RegExp Pattern Syntax" target="_blank">regul&#228;ren Ausdr&#252;cken</a> (auch Regular Expressions oder kurz RegExp genannt) zu tun, in JavaScript habe ich damit bisher nur selten gearbeitet. F&#252;r ein aktuelles Projekt musste ich aber aus einem Array von Strings die regul&#228;ren Ausdr&#252;cke erzeugen und hatte einige Zeit damit zu tun, herauszufinden wie das geht.<span id="more-47"></span></p>
<p>Regul&#228;re Ausdr&#252;cke werden in JavaScript einfach durch die Begrenzer "/" definiert, also z.B. so:</p>
<div class="igBar"><span id="ljavascript-4"><a href="#" onclick="javascript:showPlainTxt('javascript-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-4">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// RegExp-Definition</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myregexp = <span style="color: #0066FF;">/regexp/</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// Such-String</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">searchstring = <span style="color: #3366CC;">"Das mit den regexp macht Spa&#223;"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// RegExp anwenden</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">var</span> result = searchstring.<span style="color: #006600;">search</span><span style="color: #66cc66;">&#40;</span>myregexp<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// und Ergebnis ausgeben</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>result != -<span style="color: #CC0000;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span> document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"Gefunden"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">else</span> document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"Nicht gefunden"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>JavaScript erkennt anhand der Delimiter (Begrenzer) "/", dass es sich um einen regul&#228;ren Ausdruck handelt. Wenn jetzt aber das Suchmuster als Zeichenkette vorliegt, dann funktioniert das nicht. Hier ist es aber auch ganz einfach m&#246;glich, ein Objekt vom Typ RegExp zu erzeugen:</p>
<div class="igBar"><span id="ljavascript-5"><a href="#" onclick="javascript:showPlainTxt('javascript-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-5">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// JavaScript-RegExp aus Zeichenkette erzeugen</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myregexp = <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"suchmuster"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// Als 2. Parameter k&#246;nnen die RegExp-Modifier angegeben werden</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">myregexp2 = <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"suchmuster"</span>, <span style="color: #3366CC;">"ig"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Nur mal so als Tipp...</p>
<p><strong>Zusatztipp:</strong> Die Suchmuster sind normalerweise zu "escapen" (d.h. alle vorkommenden "/" durch die Variante mit vorangestelltem "\" zu ersetzten) also aus "/" wird "\/". Das ist bei der Variante aus dem String nicht notwendig. Sehr praktisch. Die regexp-relevanten Zeichen m&#252;ssen trotzdem mit Backslashes versehen werden, was nat&#252;rlich wiederum per RegExp geschehen kann (bei Bedarf einfach eine kleine Funktion basteln):</p>
<div class="igBar"><span id="ljavascript-6"><a href="#" onclick="javascript:showPlainTxt('javascript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVASCRIPT:</span>
<div id="javascript-6">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900; font-style: italic;">// Punkt escapen durch Backslash voranstellen</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mstr=mstr.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/\./g</span>,<span style="color: #3366CC;">"<span style="color: #000099; font-weight: bold;">\\</span>."</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ich w&#252;nsche ein allzeit freudiges RexExp-Hacking!</p>
<p>Was hast Du f&#252;r Erfahrungen mit RegExp gemacht? Bist Du "Fan" oder hasst Du die Teile? Hast Du einen weitergehenden Tipp zum Thema? Schreib mir Deine Meinung in den Kommentaren.</p>
<p>Wenn Du diesen Beitrag hilfreich findest, dann abonnier' doch den <a href="http://phpkuh.de/feed/" title="PHPKuh RSS-Feed" target="_blank" rel="nofollow">PHPKuh RSS-Feed</a>, um auch in Zukunft die Beitr&#228;ge rund um das Thema Webentwicklung mit PHP zu erhalten.</p>
]]></content:encoded>
			<wfw:commentRss>http://phpkuh.de/regexp-aus-string-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://phpkuh.de/hello-world/</link>
		<comments>http://phpkuh.de/hello-world/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 17:53:12 +0000</pubDate>
		<dc:creator>Chefkoch</dc:creator>
				<category><![CDATA[sonstiges]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[start]]></category>

		<guid isPermaLink="false">http://phpkuh.de/?p=1</guid>
		<description><![CDATA[Na klar, das obligatorische "Hello world!" mu&#223; nat&#252;rlich stehenbleiben, wie es sich f&#252;r ein ordentliches Techie-Blog geh&#246;rt.
Endlich kann es hier losgehen: nach etlichem Aufschub gibt es nun keine Ausrede mehr f&#252;r mich, mit den t&#228;glich unter viel Kaffee-, Musik- und manchmal auch Alkohol-Einfluss entstehenden Erfahrungen beim Basteln von Websites und -services nicht das Internet vollzuschreiben.
Ich [...]]]></description>
			<content:encoded><![CDATA[<p>Na klar, das obligatorische "Hello world!" mu&#223; nat&#252;rlich stehenbleiben, wie es sich f&#252;r ein ordentliches Techie-Blog geh&#246;rt.</p>
<p>Endlich kann es hier losgehen: nach etlichem Aufschub gibt es nun keine Ausrede mehr f&#252;r mich, mit den t&#228;glich unter viel Kaffee-, Musik- und manchmal auch Alkohol-Einfluss entstehenden Erfahrungen beim Basteln von Websites und -services nicht das Internet vollzuschreiben.<span id="more-1"></span></p>
<p>Ich freue mich drauf, meine Erfahrungen zum Thema PHP, MySQL, (X)HTML, CSS, Browser, Linux aber auch kommentierte PHP- und Tech-News und alles was mir sonst noch Spa&#223; macht in diesem Bereich zu posten und w&#252;nsche mir nat&#252;rlich einen regen Austausch zu den Themen, der f&#252;r alle Beteiligten gut ist. Wer schon &#246;fter bei Google (oder woanders) auf der Suche nach einer L&#246;sung f&#252;r ein verzwicktes Programmier-Problem f&#252;ndig wurde, weiss was ich meine....</p>
<p>Im besten Fall kann ich also durch dieses Blog ein wenig an die Opensource-Community zur&#252;ckgeben,  in Form von Tipps und Findings, die mir selbst sehr geholfen h&#228;tten (Hand-an-Stirn-Klatsch-Effekt...), und gleichzeitig durch den Austausch lernen, denn: je mehr ich weiss, umso mehr weiss ich, was ich alles noch nicht weiss...*gr&#252;bel*</p>
<p>In diesem Sinne also viel Spa&#223; bei der Lekt&#252;re und <strong>Happy PHP Hacking</strong>!</p>
]]></content:encoded>
			<wfw:commentRss>http://phpkuh.de/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

