# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = (r"(?<=regex101.*)\.NET\n"
r"class MyNewLanguage extends PureComponent {\n\n"
r" //\n"
r" // Proptypes\n\n"
r" static propTypes = {\n"
r" regex: PropTypes.string.isRequired,\n"
r" flags: PropTypes.string.isRequired,\n"
r" delimiter: PropTypes.string.isRequired,\n"
r" testString: PropTypes.string.isRequired,\n"
r" isSubstituting: PropTypes.bool.isRequired,\n"
r" isGlobal: PropTypes.bool.isRequired,\n"
r" substString: PropTypes.string\n"
r" };\n\n"
r" //\n"
r" // Control\n\n"
r" // If you need to manipulate any data, you should preferably do it in a function defined \n"
r" // on the class body here. This could for example be sanitizing data (escaping quotes, etc).\n\n"
r" //\n"
r" // Render functions\n\n"
r" render() {\n"
r" return (\n"
r" <Highlight lang=\"myNewLanguage\">\n"
r" {this._renderCode()}\n"
r" </Highlight>\n"
r" );\n"
r" }\n\n"
r" _renderCode() {\n"
r" const { regex, flags, delimiter, testString, isSubstituting, substString, isGlobal } = this.props;\n\n"
r" const codeString = new CodeString();\n"
r" \n"
r" // CodeString is a basic class that allows you to create a code snippet without having\n"
r" // to worry about indentation or newlines.\n\n"
r" // The only functions are `append`, `indent` and `toString`.\n"
r" // The implementation can be found on this page.\n\n"
r" // Create your code string here\n"
r" codeString.append(`Use string literals when ${regex} interpolating ${flags} data`);\n"
r" \n"
r" return codeString.toString();\n"
r" }\n\n"
r"}\n\n"
r"export default MyNewLangauge;")
test_str = "regex101 now has 100% .NET support"
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