Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

import re regex = re.compile(r"(export )?const (.* \= \()(.*)(\).*\()(?'fileContent'(\n.*)+)\3\.(?'varName'[^}]*)\}(?'restOfPropLine'.*$)(?'restOfFileContent'(\n.*)+>\n\);)", flags=re.MULTILINE) test_str = ("export const AffiliateAccountBIFields = (props) => (\n" " <SimpleShowLayout {...props} variant=\"one\">\n" " <UrlField source=\"bi_url\" options={{ target: '_blank' }} />\n" " <ProtectedBIConfigField source=\"bi_settings\" />\n" " </SimpleShowLayout>\n" ");\n\n" "export const AffiliateAccountGeneralFields = (props) => (\n" " <SimpleShowLayout {...props}>\n" " <TextField source=\"name\" />\n" " <ReferenceField\n" " linkType=\"show\"\n" " label=\"Platform Provider\"\n" " addLabel\n" " source=\"platform_provider_id\"\n" " reference=\"accounts/platform-providers\"\n" " allowEmpty\n" " >\n" " <TextField addLabel source=\"name\" />\n" " </ReferenceField>\n" " <ReferenceField\n" " label=\"Company\"\n" " addLabel\n" " source=\"company_id\"\n" " reference=\"companies\"\n" " linkType=\"show\"\n" " >\n" " <TextField addLabel source=\"name\" />\n" " </ReferenceField>\n" " <AccountManagerField\n" " label=\"Account Manager\"\n" " source=\"account_manager_id\"\n" " addLabel\n" " />\n" " <PortfolioField label=\"Portfolio\" source=\"portfolio_id\" addLabel />\n" " <FunctionField\n" " label=\"Status\"\n" " addLabel\n" " source=\"activity_status\"\n" " render={(record) => {\n" " if (!record.activity_status) return null;\n" " const humanizedStatus = get(\n" " ACTIVITY_STATUS_OPTIONS,\n" " `${record.activity_status}.name`\n" " );\n" " if (!humanizedStatus) {\n" " // eslint-disable-next-line no-console\n" " console.warn(`Cannot obtain humanized value for activity_status: ${record.activity_status}`);\n" " }\n" " return (\n" " <TextField\n" " source=\"activity_status\"\n" " record={{\n" " ...record,\n" " activity_status: humanizedStatus || record.activity_status,\n" " }}\n" " />\n" " );\n" " }}\n" " />\n" " <UrlField source=\"affiliate_system_link\" options={{ target: '_blank' }} />\n" " <CopyToClipboardField source=\"username\">\n" " <TextField source=\"username\" />\n" " </CopyToClipboardField>\n" " <ProtectedField source=\"password\" />\n" " <CopyToClipboardField source=\"email\">\n" " <TextField source=\"email\" />\n" " </CopyToClipboardField>\n" " <TextField source=\"security_question\" />\n" " <ProtectedField source=\"security_answer\" />\n" " <TextField source=\"type\" />\n" " <BooleanField source=\"tracking_enabled\" />\n" " <TextField source=\"tracking_variable_name\" />\n" " <TextField source=\"external_affiliate_id\" />\n" " <TextField source=\"revenue_posting_code\" />\n" " <BooleanField source=\"loss_carry_forward\" />\n" " <DateField source=\"updated_at\" locales=\"en-GB\" showTime />\n" " <DateField source=\"created_at\" locales=\"en-GB\" showTime />\n" " </SimpleShowLayout>\n" ");\n\n" "export const AffiliateAccountTabs = (props) => {\n" " if (!props.record) {\n" " return null;\n" " }\n\n" " return (\n" " <TabbedShowLayout>\n" " <AffiliateAccountGeneralFields {...props} label=\"General\" />\n" " <AffiliateAccountBrands {...props} label=\"Brands\" />\n" " <AffiliateAccountDeals {...props} label=\"Deals\" />\n" " {props.hasBIPermission && (\n" " <AffiliateAccountBIFields {...props} label=\"BI Settings\" />\n" " )}\n" " </TabbedShowLayout>\n" " );\n" "};\n" "AffiliateAccountTabs.propTypes = {\n" " record: PropTypes.object,\n" " hasBIPermission: PropTypes.bool.isRequired,\n" "};\n\n" "export const Show = (props) => (\n" " <AutoLoginStatusDialog messages={messages}>\n" " <AORShow\n" " {...props}\n" " title={(\n" " <Title\n" " resource=\"Affiliate Account\"\n" " type=\"show\"\n" " buttons={[\n" " <FavoriteButton\n" " record={{ _id: props.match.params.id }}\n" " resource={props.resource}\n" " style={{ height: '25px' }}\n" " />,\n" " ]}\n" " />\n" " )}\n" " actions={(\n" " <ActionsPanel\n" " customButtons={[\n" " <AutoLoginButton\n" " record={{ _id: props.match.params.id }}\n" " resource={props.resource}\n" " resourceConfig={autoLoginConfig}\n" " label=\"Auto Login\"\n" " />,\n" " ]}\n" " />\n" " )}\n" " >\n" " <AffiliateAccountTabs hasBIPermission={props.hasBIPermission} />\n" " </AORShow>\n" " <NotesView isShow match={props.match} resource={props.resource} />\n" " </AutoLoginStatusDialog>\n" ");\n" "Show.propTypes = {\n" " match: PropTypes.shape({\n" " params: PropTypes.shape({\n" " id: PropTypes.string,\n" " }),\n" " }),\n" " resource: PropTypes.string,\n" " hasBIPermission: PropTypes.bool.isRequired,\n" "};\n\n" "export default connect((state) => ({\n" " hasBIPermission: checkPermission(state.auth.permissions, '*', 'bi_user'),\n" "}))(Show);\n") subst = "$1const $2{ ${varName}, ...$3 }$4${fileContent}${varName}}${restOfPropLine}${restOfFileContent}" result = regex.sub(subst, test_str) if result: print(result)

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