Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

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

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm