Python : ChatBot(using Regular Expression )
Simple Chatbot
EchoBot_04: using class
Google Search Bot
Regular Expression.
A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern.
Let's make a more flexible chatbot using Re.
import re m = re.search("[a-zA-Z0-9]", "0")
import re matched = re.search("[a-zA-Z|_][a-zA-Z0-9_]*", "data") if matched: print(matched.group())
print(re.search(r"\d\d\d","119"))
m = re.search(r"([a-zA-Z|_][a-zA-Z0-9]*):(\d+)-(\d+)-(\d+)", "jung:010-1234-5678")
Let's use all four matching functions from now on. - search() - match() - findall() - finditer()
import re
p = re.compile(r"(\d+)|([a-zA-z][\w]*)")
result = p.findall("int main() { int i = 10; for(i=1; i<10; i++)" )
print(result)
Python_8장_RE_07_Chatbot_1: https://colab.research.google.com/drive/124-Nkv46whz7eLXsxsT8frzgOFctj0Au
Python_8장_RE_07_Chatbot_2: https://colab.research.google.com/drive/1MmWzmPnmfdVnRU4QOIY43gaZ7i3Qt9cq
WebCrawling
Python_8장_RE_08_WebCrawling_01: https://colab.research.google.com/drive/1EvQpXRgTBymX4yzWfxPoV7fyj91IDAPQ
Comments
Post a Comment