Quellcode durchsuchen

slang.tcl: deal with word from an inexact match in word regex

Will Storey vor 13 Jahren
Ursprung
Commit
668c0c87f0
1 geänderte Dateien mit 5 neuen und 1 gelöschten Zeilen
  1. 5 1
      slang.tcl

+ 5 - 1
slang.tcl

@@ -33,7 +33,9 @@ namespace eval ud {
 	variable url http://www.urbandictionary.com/define.php
 	variable url_random http://www.urbandictionary.com/random.php
 
-	variable word_regexp {<td class='word'>\s*?<span>\s*?(.*?)\s*?</span>}
+	# regex to find the word 
+	# if we have an inexact match, then we may have the word wrapped in <a/>.
+	variable word_regexp {<td class='word'>\s*?<span>\s*(?:<a href=\"[^>]+\">)?(.*?)(?:</a>)?\s*?</span>}
 	variable list_regexp {<td class='text'.*? id='entry_.*?'>.*?</td>}
 	variable def_regexp {id='entry_(.*?)'>.*?<div class="definition">(.*?)</div>}
 
@@ -134,6 +136,8 @@ proc ud::http_fetch {url http_query} {
 	if {$ncode != 200} {
 		error "HTTP fetch error. Code: $ncode"
 	}
+
+	# pull out the word.
 	if {![regexp -- $ud::word_regexp $data -> word]} {
 		error "Failed to parse word"
 	}