<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: editplus code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 23 Jul 2008 18:50:29 GMT</pubDate>
    <description>DZone Snippets: editplus code</description>
    <item>
      <title>Finding line number when matching text</title>
      <link>http://snippets.dzone.com/posts/show/1638</link>
      <description>I use python to do some text analysis.&lt;br /&gt;I load all the text file into a string and match it with&lt;br /&gt;a regexp. Now I want to know the line number of a match.&lt;br /&gt;I can use the line number to lookup inside the text.&lt;br /&gt;(in this case using EditPlus)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;src = open('2.htm').read()&lt;br /&gt;pattern = '&lt;P&gt;([^&lt;]+)&lt;SUP&gt;'  # or anything else&lt;br /&gt;for m in re.finditer(pattern, src):&lt;br /&gt;	start = m.start()&lt;br /&gt;	lineno = src.count('\n', 0, start) + 1&lt;br /&gt;	offset = start - src.rfind('\n', 0, start)&lt;br /&gt;	word = m.group(1)&lt;br /&gt;	print "2.htm(%s,%s): %s" % (lineno, offset, word)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Editplus allow me to double click at the output printed&lt;br /&gt;and jump to the exact position using the given lineno, offset.</description>
      <pubDate>Mon, 06 Mar 2006 10:46:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1638</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
