# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"const.*=.*{+$"
test_str = ("exports.async_createUser = async (user, required) => {\n"
"exports.async_createUser = async (user, required) => \n\n"
"const test = function(a,b) => {\n"
"const test = (a,b) => {\n"
"const test = a => {\n"
"const async_getInfAuthToken = async () => {\n"
"const convertFromStateABV = async abv => {\n"
"const customField = infUser.custom_fields.filter(index => {\n"
"const thing = new user({\n"
"// const thing = new user({\n"
"// inf.updateWedding(weddingId);\n"
"inf.setMilestoneDate(req.user, 8);\n"
"}); //User email >> Spouse email (42)\n"
"exports.infCreate = function(req, callback) {\n"
"const user = await User.findOne({ _id: wedding.users[numUser] });\n\n"
"const test = function(a,b) \n"
"const i = require(./stuff)\n"
"// const userC = require(\"./users\");\n\n"
"const User = require(\"./../models/user\");\n"
"const Utils = require(\"./../utils\");\n"
"const userC = require(\"./users\");\n"
"const Wedding = require(\"./../models/wedding\");\n"
"const config = require(\"./../config\");\n"
"const request = require(\"request-promise\");\n"
"const sms = require(\"./smss\");\n"
"const email = require(\"./emails\");\n"
"const contacts = require(\"./contacts\");\n\n\n"
"\"error [inf.getNumberOfContactsFromWeddingID] : \" + //\n"
"inf.applyTagToUser(userList[i].inf_id, [ //\n"
"// inf.setMilestoneDate(userList[i], 8);\n"
"inf.applyTagToUser(u.inf_id, [564]); //[Fulfillment _ 110 _ DLY _ LM _ WT - couples _ v01 _ START]\n")
matches = re.finditer(regex, test_str, 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