{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n", "False\n" ] } ], "source": [ "# Write a Python program to check that a string contains only a certain set of characters (in this case a-z, A-Z and 0-9).\n", "# Input\n", "# \"ABCDEFabcdef123450\"\n", "# \"*&%@#!}{\"\n", "# Output\n", "# True \n", "# False\n", "\n", "import re\n", "def is_allowed_specific_char(string):\n", " charRe = re.compile(r'[^a-zA-Z0-9.]')\n", " string = charRe.search(string)\n", " return not bool(string)\n", "\n", "print(is_allowed_specific_char(\"ABCDEFabcdef123450\")) \n", "print(is_allowed_specific_char(\"*&%@#!}{\"))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }