# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"'\$([\d]*)[\.]?(\d+)'"
test_str = ("#Test-2019-8\n\n"
"#1.'do+g'\n"
"dog, doooog, abcdogef,\n"
"asdooooijk dooog asdoogghj\n"
"'dog', 'doooog', 'abcdogef'\n\n"
"#2. 'ab*d'\n"
"ad, abd, abbbd\n"
"'ad', 'abd', 'abbbbd'\n"
"'sad', 'cabd', 'abbbds'\n\n"
"#3. '[xy]{2}AB'\n"
"'xxAB', 'xyAB','yyAB' '2xxAB'\n\n"
"#4. '[a-z].?'\n"
"'aA', 'b9', 'z' 'bX'\n"
"'aB z8 b6'\n\n"
"#5. '5[abc]?ef'\n"
"'5aef', 'a5bef', '5ef' '5ef'\n\n"
"#6. Taiwan ID : '([A-Z])([12])(\\d{8})','[A-Z][12]\\d{8}'\n"
"'A102926987', 'B212345678'\n\n"
"#7. mobile tel_num:'(09)(\\d\\d)[-\\s](\\d{3})[-\\s](\\d{3})' \n"
"'0988 123 456', '0978-456-789'\n"
"# : '09\\d\\d[-\\s]\\d\\d\\d'\n"
" '0924-357'\n\n"
"#8. Home tel_num:\n"
"# '([\\(]?\\d\\d[\\)-]?)([\\d]{4})([-\\s]{1}[\\d]{4})' \n"
"'(02)2257 3150', '02-2250-3457','(12)2245 3214'\n"
"# '[\\(]?(0[23])[\\)-]?(\\d{4})'\n"
"'(02)2345', '03-1348'\n\n"
"#9. Date Time:yyyy/mm/dd \n"
"#'(20[12]\\d)[-\\/]([1]?[\\d])[-\\/]([1-3][\\d])'\n"
"'2019/1/25', '2018-12-31'\n"
"#'(20[12]\\d)[-\\/]([01]\\d)[-\\/](\\d{2})'\n"
"'2019/01/15' ,'2020-11-28'\n\n"
"#10. floating number: '\\$([\\d]*)[\\.]?(\\d+)'\n"
"'$123.34', '$2345' '$0.234' ,'1.87'\n\n")
matches = re.finditer(regex, test_str, re.IGNORECASE | re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html