Hi Achim,

On 21 March 2012 01:01, Achim Gratz <Stromeko@nexgo.de> wrote:
Sankalp <sankalpkhare@gmail.com> writes:
> i.e. at the end I get this error - Args out of range: 0, 0

Well, it tells you that the input to that function was unexpected.  You
could do M-: (setq debug-on-error) and see what the backtrace turns up.


Here's what the backtrace says :

Debugger entered--Lisp error: (args-out-of-range 0 0)
  replace-match(#("\n#+BEGIN_html\n<pre class=\"src src-python\"><span style=\"color: #a020f0;\">import</span> re     <span style=\"color: #b22222;\"># import the module</span>\n\n<span style=\"color: #000000; background-color: #ffffff;\">match</span> = re.search(r<span style=\"color: #8b2252;\">'iiit'</span>,<span style=\"color: #8b2252;\">'iiit hyderabad is in India'</span>)\n<span style=\"color: #7a378b;\">print</span> match.group()\n\n<span style=\"color: #000000; background-color: #ffffff;\">match</span> = re.search(r<span style=\"color: #8b2252;\">'iiit'</span>,<span style=\"color: #8b2252;\">'iiit is in India. IIIT offers CS degrees too.'</span>)\n<span style=\"color: #7a378b;\">print</span> match.group()\n\n<span style=\"color: #000000; background-color: #ffffff;\">match</span> = re.search(r<span style=\"color: #8b2252;\">'he'</span>,<span style=\"color: #8b2252;\">'this is the eiffel tower. The eiffel tower is in France.'</span>)\n<span style=\"color: #7a378b;\">print</span> match.group()\n\n</pre>\n\n#+END_html\n" 0 14 (original-indentation 3) 14 961 (org-native-text t org-example t org-protected t original-indentation 3) 961 973 (original-indentation 3)) t t)
  org-export-replace-src-segments-and-examples()
  org-export-preprocess-string(#("#+TITLE: Regular Expressions in Python\n#+STARTUP: overview   (others are showall)\n#+STARTUP: hidestars\n#+OPTIONS: toc:nil\n\n* Introduction\n\n** Mathematical understanding of regular expressions\n\n\n** regular expressions and Operations\n - sequencing :: by default\n - grouping  ::  [abc]  one of any characters in the group\n - alternation :: |\n - repetition :: a* and a+ and a?\n - complementation :: ^\n\n\n\n** From strings to Regular expressions in Python ::\n   Using the 'r' keyword to indicate regular expressions\n   instead of strings.\n\n\n** Metacharacters\n\n  - $ ::\n  - ^ :: inside a group, specifies complementation\n  - \\ :: used to escape from the default meaning to a new meaning.  Eg, \\w, \\[, \\\\, etc.\n  - . ::\n\n** Special symbols ::\n\n  - \\d :: matches any decimal\n  - \\s :: any whitespace character [\\t\\n\\r\\f\\v]\n  - \\w :: any alphanumeric character\n  - .  :: matches any character except newline\n  - more\n\n\n** Compiling regexes\n\n - pat = re.compile(r\"ab*\") :: This \"compiles\" the regular\n      expression =ab*=.  The result is a pattern object.\n\n** Using regexes\n\n\n - re.match(r<pattern>, string) :: returns an object that contains\n      a match at the BEGINNING of the string, else None.\n\n - re.search(r<pattern>, string) :: returns an object that contains a\n      match ANYWHERE in the string, else None\n\n - re.findall(r<pattern>, string) :: returns a list that\n      contains all the matches of the pattern in the string.\n\n - re.finditer(r<pattern>, string) :: returns an iterator that\n      contains all the matches of the pattern in the string.\n\n\n** Operations on the matched object\n\n  - group() :: returns the string matched\n  - start() :: returns the start position of the match\n  - end() :: returns the end position of the match\n  - span() :: returns the group of starting and ending positions.\n\n* Examples\n\n  We cover some simple examples of regular expressions\n\n** Basic examples\n\n   #+begin_src python :results output :exports both\n     import re     # import the module\n\n     match = re.search(r'iiit','iiit hyderabad is in India')\n     print match.group()\n\n     match = re.search(r'iiit','iiit is in India. IIIT offers CS degrees too.')\n     print match.group()\n\n     match = re.search(r'he','this is the eiffel tower. The eiffel tower is in France.')\n     print match.group()\n\n   #+end_src\n\n   #+results:\n   : iiit\n   : iiit\n   : he\n\n\n** Using special characters\n\n*** The =^= and =$=\n\n    #+begin_src python :results output :exports both\n      import re\n      match = re.search(r'^t123','this t123')\n      print match   # match is None\n\n      match = re.search(r'^t123','t123 the')\n      print match.group()\n\n      match = re.search(r't123$','this t123')\n      print match.group()\n\n      match = re.search(r't123$','t123 the')\n      print match   # match is None\n\n    #+end_src\n\n    #+results:\n    : None\n    : t123\n    : t123\n    : None\n\n*** The =*= and =+=\n\n    #+begin_src python :results output :exports both\n      import re\n\n      match = re.search(r'a*','red box in red light')\n      print match.group()    # Null String, not None\n\n      match = re.search(r'a+','red box in red light')\n      print match            # None\n\n      match = re.search(r'a*','a red box in the red light')\n      print match.group()\n    #+end_src\n\n    #+results:\n=\nNone\na\n=    :\n    : None\n    : a\n\n*** The =?= and =.=\n\n    #+begin_src python :results output :exports both\n      import re\n\n      match = re.search(r'a?','red box in red light')\n      print match.group() #Null String, not None\n\n      # pattern is ={'a'}\n      match = re.search(r'a.','red box in red light')\n      print match # None\n\n      match = re.search(r'a.','a red box in the red light')\n      print match.group()\n    #+end_src\n\n    #+results:\n=\nNone\na \n=    :\n    : None\n    : a\n\n*** The =\\w, \\d, \\W= etc.\n\n    #+begin_src python :results output :exports both\n      import re\n\n      match = re.search(r'a\\w+','pelican')\n      print match.group()\n\n      match = re.search(r'a\\w+','mica')\n      print match #None\n\n      match = re.search(r'a\\W','pelican is a bird')\n      print match.group()\n\n      match = re.search(r'a\\d','His password is a12@')\n      print match.group()\n\n    #+end_src\n\n    #+results:\n    : an\n    : None\n    : a \n    : a1\n\n*** Using =[]=\n\n    #+begin_src python :results output :exports both\n      import re\n\n      match = re.search(r'[a-d]+pocalypse','apocalypse')\n      print match.group()\n\n      match = re.search(r'[a-d]+arwin','arwin')\n      print match # None\n\n    #+end_src\n\n    #+results:\n    : apocalypse\n    : None\n\n*** Using =|=\n\n    #+begin_src python :results output :exports both\n      import re\n\n      match = re.search(r'[t|f]ree','tree is free')\n      print match.group()\n\n      match = re.search(r'[t|f]ree','bree')\n      print match #None\n\n    #+end_src\n\n    #+results:\n    : tree\n    : None\n\n*** Escaping special characters\n\n    #+begin_src python :results output :exports both\n      import re\n\n      match = re.search(r'2\\+3','Compute value of 2+3')\n      print match.group()\n\n    #+end_src\n\n    #+results:\n    : 2+3\n\n\n*** Regex to match a floating point number\n\n    #+begin_src python :results output :exports both\n      import re\n      \n      match = re.search(r'[0-9]+\\.[0-9]+','pi is 3.14')\n      print match.group()\n      \n      match = re.search(r'[0-9]+\\.[0-9]+','There are 3 primary colors.')\n      print match #None\n      \n      match = re.search(r'[0-9]+\\.[0-9]+','The date is 15.02.2012')\n      print match.group() # This matches! It should not! Students should fix this\n    #+end_src\n\n    #+results:\n    : 3.14\n    : None\n    : 15.02\n\n** Using groups and other advanced constructs\n*** Groups\n    #+begin_src python :results output :exports both\n      import re\n      \n      match = re.search(r'([0-9]*\\w+&),([0-9]+)','This&,9')\n      print match.group()\n      print match.group(0)\n      print match.group(1)\n      print match.group(2)\n      \n    #+end_src\n\n    #+results:\n    : This&,9\n    : This&,9\n    : This&\n    : 9\n\n*** =findall=\n    #+begin_src python :results output :exports both\n      import re\n      \n      match = re.findall(r'[0-9]+','123 is another string like 456')\n      print match\n      \n    #+end_src\n\n    #+results:\n    : ['123', '456']\n\n*** =compile=\n    Internally, every regular expression is translated (i.e,\n    compiled) into an internal representation (an object).  This\n    compiled object can be saved and reused, as the\n    following examples show.\n\n    #+begin_src python :results output :exports both\n      import re\n      \n      pattern = re.compile(r'[0-9]+')\n      matchlist = pattern.findall('123 is another string like 456')\n      print matchlist\n      \n    #+end_src\n\n    #+results:\n    : ['123', '456']\n\n* References\n\n  1. http://docs.python.org/library/re.html\n  2. http://code.google.com/edu/languages/google-python-class/regular-expressions.html\n  3. http://www.regular-expressions.info/python.html\n\n" 0 8 (fontified t face org-document-info-keyword font-lock-fontified t) 8 9 (fontified t face font-lock-comment-face) 9 38 (fontified t face org-document-title font-lock-fontified t) 38 39 (fontified t) 39 81 (fontified t face org-meta-line font-lock-fontified t) 81 82 (fontified t font-lock-fontified t face org-meta-line) 82 102 (fontified t face org-meta-line font-lock-fontified t) 102 103 (fontified t font-lock-fontified t face org-meta-line) 103 121 (fontified t face org-meta-line font-lock-fontified t) 121 122 (fontified t font-lock-fontified t face org-meta-line) 122 123 (fontified t) 123 125 (fontified t face org-level-1) 125 137 (fontified t face org-level-1) 137 139 (fontified t) 139 140 (fontified t face org-hide) 140 142 (fontified t face org-level-2) 142 191 (fontified t face org-level-2) 191 194 (fontified t) 194 195 (fontified t face org-hide) 195 197 (fontified t face org-level-2) 197 231 (fontified t face org-level-2) 231 235 (fontified t) 235 248 (fontified t face (bold)) 248 263 (fontified t) 263 275 (fontified t face (bold)) 275 322 (fontified t) 322 336 (fontified t face (bold)) 336 342 (fontified t) 342 355 (fontified t face (bold)) 355 376 (fontified t) 376 394 (fontified t face (bold)) 394 400 (fontified t) 400 401 (fontified t face org-hide) 401 403 (fontified t face org-level-2) 403 451 (fontified t face org-level-2) 451 509 (fontified t) 509 1804 (fontified nil) 1804 1805 (fontified t) 1805 1807 (fontified t face org-level-1) 1807 1815 (fontified t face org-level-1) 1815 1873 (fontified t) 1873 1874 (fontified t face org-hide) 1874 1876 (fontified t face org-level-2) 1876 1890 (fontified t face org-level-2) 1890 1892 (fontified t) 1892 1943 (fontified t font-lock-fontified t font-lock-multiline t face org-block-begin-line) 1943 1944 (fontified t font-lock-fontified t font-lock-multiline t face org-block-begin-line) 1944 1949 (fontified t font-lock-fontified t font-lock-multiline t face nil) 1949 1950 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-keyword-face) 1950 1955 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-keyword-face) 1955 1956 (fontified t font-lock-fontified t font-lock-multiline t face nil) 1956 1963 (fontified t font-lock-fontified t font-lock-multiline t face nil) 1963 1964 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-comment-face) 1964 1983 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-comment-face) 1983 1984 (fontified t font-lock-fontified t font-lock-multiline t face nil) 1984 1989 (fontified t font-lock-fontified t font-lock-multiline t face nil) 1989 1990 (fontified t font-lock-fontified t font-lock-multiline t face py-variable-name-face) 1990 1994 (fontified t font-lock-fontified t font-lock-multiline t face py-variable-name-face) 1994 1995 (fontified t font-lock-fontified t font-lock-multiline t face nil) 1995 2008 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2008 2009 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2009 2014 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2014 2015 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2015 2016 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2016 2043 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2043 2044 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2044 2050 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2050 2051 (fontified t font-lock-fontified t font-lock-multiline t face py-builtins-face) 2051 2055 (fontified t font-lock-fontified t font-lock-multiline t face py-builtins-face) 2055 2056 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2056 2076 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2076 2077 (fontified t font-lock-fontified t font-lock-multiline t face py-variable-name-face) 2077 2081 (fontified t font-lock-fontified t font-lock-multiline t face py-variable-name-face) 2081 2082 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2082 2095 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2095 2096 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2096 2101 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2101 2102 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2102 2103 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2103 2149 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2149 2150 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2150 2156 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2156 2157 (fontified t font-lock-fontified t font-lock-multiline t face py-builtins-face) 2157 2161 (fontified t font-lock-fontified t font-lock-multiline t face py-builtins-face) 2161 2162 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2162 2182 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2182 2183 (fontified t font-lock-fontified t font-lock-multiline t face py-variable-name-face) 2183 2187 (fontified t font-lock-fontified t font-lock-multiline t face py-variable-name-face) 2187 2188 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2188 2201 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2201 2202 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2202 2205 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2205 2206 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2206 2207 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2207 2264 (fontified t font-lock-fontified t font-lock-multiline t face font-lock-string-face) 2264 2265 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2265 2271 (fontified t font-lock-fontified t font-lock-multiline t face nil) 2271 2272 (fontified t font-lock-fontified t font-lock-multiline t face py-builtins-face) 2272 2277 (fontified t font-lock-fontified t font-lock-multiline t face py-builtins-face) 2277 2291 (fontified t font-lock-fontified t font-lock-multiline t) 2291 2292 (fontified t font-lock-fontified t font-lock-multiline t) 2292 2304 (fontified t font-lock-fontified t font-lock-multiline t face org-block-end-line) 2304 2305 (fontified t face org-block-end-line) 2305 6663 (fontified nil) 6663 6664 (fontified t) 6664 6666 (fontified t face org-level-1) 6666 6676 (fontified t face org-level-1) 6676 6683 (fontified t) 6683 6720 (fontified t org-no-flyspell t mouse-face highlight face org-link keymap (keymap ... ... ...)) 6720 6721 (fontified t org-no-flyspell t mouse-face highlight face org-link keymap (keymap ... ... ...) rear-nonsticky (mouse-face highlight keymap invisible intangible help-echo org-linked-text)) 6721 6727 (fontified t) 6727 6807 (fontified t org-no-flyspell t mouse-face highlight face org-link keymap (keymap ... ... ...)) 6807 6808 (fontified t org-no-flyspell t mouse-face highlight face org-link keymap (keymap ... ... ...) rear-nonsticky (mouse-face highlight keymap invisible intangible help-echo org-linked-text)) 6808 6814 (fontified t) 6814 6860 (fontified t org-no-flyspell t mouse-face highlight face org-link keymap (keymap ... ... ...)) 6860 6861 (fontified t org-no-flyspell t mouse-face highlight face org-link keymap (keymap ... ... ...) rear-nonsticky (mouse-face highlight keymap invisible intangible help-echo org-linked-text)) 6861 6863 (fontified t)) :emph-multiline t :for-backend html :skip-before-1st-heading nil :drawers nil :todo-keywords t :tasks t :tags not-in-toc :priority nil :footnotes t :timestamps t :archived-trees headline :select-tags ("export") :exclude-tags ("noexport") :add-text nil :LaTeX-fragments t)
  org-export-as-html(nil)
  call-interactively(org-export-as-html)
  org-export(nil)
  call-interactively(org-export nil nil)

I'm not sure what to make of it, though.
 
> Strangely, doing an export for the 2nd time, without deleting the
> output html file manages to do it successfully without throwing any
> errors.

There's a correction. On the first pass, no html file is generated. But I feel it must have something to do with the Python shell buffers that get created (and are left with the comint:run status) after each export.
 

Which seems to hint at some undeclared variable that is brought into
scope by the first run.


Regards,
Achim.
--
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds



thanks for the prompt response.

--
Sankalp


*******************************************************
If humans could mate with software, I'd have org-mode's
babies.
                          --- Chris League on Twitter.
               http://orgmode.org/worg/org-quotes.html
*******************************************************