<?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>Anna Filina &#187; regex</title>
	<atom:link href="http://annafilina.com/blog/tag/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://annafilina.com/blog</link>
	<description>I fix stuff</description>
	<lastBuildDate>Wed, 04 Jan 2012 14:56:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>lastIndexOf with RegEx?</title>
		<link>http://annafilina.com/blog/lastindexof-with-regex/</link>
		<comments>http://annafilina.com/blog/lastindexof-with-regex/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 17:38:54 +0000</pubDate>
		<dc:creator>Anna</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://annafilina.com/blog/?p=193</guid>
		<description><![CDATA[I was quite surprised that Flex did not have a way to get the index of the LAST matching substring. I want get the index of a word&#8217;s first character based on the cursor&#8217;s position (I&#8217;m working with the text property of a UITextField).
To achieve that I&#8217;m getting all text in front of that word: text.substring(0,<div><a href="http://annafilina.com/blog/lastindexof-with-regex/">Read the rest...</a></div><br />]]></description>
			<content:encoded><![CDATA[<p>I was quite surprised that Flex did not have a way to get the index of the LAST matching substring. I want get the index of a word&#8217;s first character based on the cursor&#8217;s position (I&#8217;m working with the text property of a UITextField).</p>
<p>To achieve that I&#8217;m getting all text in front of that word: text.substring(0, cursorPosition). Then, I simply want to search for the last non-word character (\W), if there is any. That way, I can have the index of the first character of the word.</p>
<p>So to get the last non-word character, I can&#8217;t use lastIndexOf() because it doesn&#8217;t support RegEx, I can&#8217;t use match() because it returns an array of substrings instead of indices and I can&#8217;t use search() because it returns the first index, not the last.</p>
<p>There is a way around the missing &#8220;searchLast()&#8221; and &#8220;searchAll()&#8221; functions.</p>
<p>I get a substring before the cursorPosition: text.substring(0, cursorPosition)<br />
I loop through all characters backwards and check if it&#8217;s a non-word char.<br />
Once I find it, I record the index at which it was found. </p>
<p>There might be other ways to get the beginning of a word based on cursor position, so don&#8217;t hesitate to share them. I really hope that the next SDK version will come with searchLast() and searchAll() functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://annafilina.com/blog/lastindexof-with-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

