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

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"[\s]*([\/+\s\w@'\,\.()\-\*\-\>\<\_\"]*)?[\n]*UFUNCTION[(]([\w<>\s\(\)\=\,\"\| ]*|\n]*)[\)]\n\s(virtual)*\s*(static)*\s*(\w+\&?\*?)\s(\w+)[(]([\w<>\s,&\*]*|\n]*)[)][\s]*([const]*)" test_str = ("// Fill out your copyright notice in the Description page of Project Settings.\n\n" "#pragma once\n\n" "#include \"CoreMinimal.h\"\n" "#include \"GM_Stepper.h\"\n" "#include \"Kismet/BlueprintFunctionLibrary.h\"\n" "#include \"StepperTypes.h\"\n" "#include \"Encoder/EncodeData.h\"\n" "#include \"Components/TextBlock.h\"\n" "#include \"BFL_Stepper.generated.h\"\n\n\n\n" "/**\n" " * \n" " */\n" "UCLASS()\n" "class STEPPER_API UBFL_Stepper : public UBlueprintFunctionLibrary\n" "{\n" " GENERATED_BODY()\n\n" "public:\n" " // Returns a copy of the current rendering LogPacket\n" " // For use ONLY during render time\n" " // Will be invalid otherwise\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Core\")\n" " static FLogPacket& GetCurrentLogPacket(bool& Success);\n\n" " // Updates the log packet sources in memory\n" " UFUNCTION(BlueprintCallable, Category = \"Stepper|Core\")\n" " static bool UpdatePacket(FLogPacket NewPacket);\n\n" " // Returns a copy of the requested MetaData from the relevant core\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Core\")\n" " static FGenericMetaTag GetMetaTag(FLogPacket ReferencePacket, FName MetaTag, bool& bIsValid);\n" " \n" " // Returns a copy of the requested MetaData from the supplied packet\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Core\")\n" " static FGenericMetaTag GetMetaTag_Explicit(FLogPacket ReferencePacket, FName MetaTag, bool& bIsValid);\n\n" " // Returns a logLine for this LogPacket by a LineId\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Core\")\n" " static bool GetLogLineInId(FLogPacket ReferencePacket, int32 inId, FActionLine& LineData);\n\n" " // Returns a logLine for this LogPacket by seeking from a specific line\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Core\")\n" " static bool GetNextActionByType(FLogPacket ReferencePacket, FAction RefAction, FName NextActionName, bool bShouldDebug, FActionLine& Action);\n" " \n" " // Updates the LogPacket in memory and text file \n" " UFUNCTION(BlueprintCallable, Category = \"Stepper|Core\")\n" " static void UpdateGenericTag(FLogPacket ReferencePacket, FGenericMetaTag MetaTag);\n\n" " // Get the saved user settings\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|User Settings\")\n" " static bool GetUserSettings(FUserSettings& Settings);\n\n" " // Get the saved capture resolution\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|User Settings\")\n" " static FIntPoint GetCaptureResolution();\n\n" " // Get the saved output resolution\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|User Settings\")\n" " static FIntPoint GetOutputResolution();\n\n" " // Get the root output folder for this log\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|User Settings\")\n" " static FString GetLogOutputFolder();\n\n" " // Gets the saved resources folder\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|User Settings\")\n" " static FString GetResourcesFolder();\n\n" " // Get a reference to the active UStepperObject\n" " // Can be nullptr\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Statics\")\n" " static UStepperCore* GetStepper();\n\n" " // Get the currently rendered stepper frame number\n" " // Return -1 if not rendering\n" " UFUNCTION(BlueprintPure, Category = \"Stepper|Statics\")\n" " static int32 GetStepperFrame();\n\n" " // Checks if a file is of type \"png\", \"jpg\", \"mp4\" or \"mov\"\n" " UFUNCTION(BlueprintPure)\n" " static bool bIsMediaFile(FString FileName);\n\n" " // Get the language of the inputted log packet\n" " UFUNCTION(BlueprintPure)\n" " static FString GetLogLanguage(FLogPacket LogPacket);\n\n" " // Get the packet's framerate\n" " UFUNCTION(BlueprintPure, meta=(CompactNodeTitle=\"FR\", Keywords = \"FrameRate, Frame, Rate\"))\n" " static FFrameRate GetPacketFrameRate(FLogPacket Packet);\n" " // Get the rendered framerate\n" " UFUNCTION(BlueprintPure, meta=(CompactNodeTitle=\"FR\", Keywords = \"FrameRate, Frame, Rate\"))\n" " static bool GetRenderedFrameRate(FFrameRate& FrameRate);\n" " // Get the packet's start timecode\n" " UFUNCTION(BlueprintPure, meta=(CompactNodeTitle=\"STC\", Keywords = \"Timecode, Time, Code, TC\"))\n" " static FTimecode GetPacketStartTimecode(FLogPacket Packet);\n" " // Get the packet's end timecode\n" " UFUNCTION(BlueprintPure, meta=(CompactNodeTitle=\"ETC\", Keywords = \"Timecode, Time, Code, TC\"))\n" " static FTimecode GetPacketEndTimecode(FLogPacket Packet);\n" " //Get the timecode data struct from the currently loaded LogPackt's MetaData\n" " UFUNCTION(BlueprintCallable, BlueprintPure, Category = \"Stepper|XML|Helpers\")\n" " static FTimecodeData GetPacketTimecodeData(FLogPacket Packet);\n\n\n" " UFUNCTION()\n" " static bool bIsDllLoaded(FString DllName);\n\n" " // Get a reference to the active game mode\n" " UFUNCTION(BlueprintCallable)\n" " static AGM_Stepper* GetGameMode();\n\n" " UFUNCTION()\n" " static ELogRenderStatus QtChangeFile(FLogPacket& LogPacket, FCameraData& CameraData, int32 Iteration);\n" " UFUNCTION()\n" " static ELogRenderStatus QtChangeFile_Scatter(FLogPacket& LogPacket, FCameraData& CameraData, int32 ScatterIndex, FName ScatterTag, FTimecode ClipTc, int32 Iteration);\n" " UFUNCTION()\n" " static ELogRenderStatus RunQtBat(FString BatLoc, FString Dir);\n\n" " UFUNCTION()\n" " static int CheckLine(FString Line);\n" " // Break a TextBox's text into lines\n" " UFUNCTION(BlueprintCallable)\n" " static void BreakTextBox(UTextBlock* TextBox, int32 MaxLineSize);\n\n" " //Takes a snapshot of a widget and returns it as a render target\n" " UFUNCTION(BlueprintCallable, Category = \"Stepper|Helpers\", meta=(DisplayName=\"Render Target From Widget With Alpha\"))\n" " static UTextureRenderTarget2D* RtFromWidget_Alpha(UUserWidget* const Widget, FVector2D Size);\n\n" " //Adds a prefix 0 for numbers below 10 (i.e 6 -> 06)\n" " UFUNCTION(BlueprintCallable, BlueprintPure, Category = \"Stepper|Helpers\")\n" " static void IntToPaddedString(int32 Int, FString& PaddedString);\n\n\n" " \n" "};\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