Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?<!\w)\b[A-Z]+[\_]*[A-Z]*\b(?=\s)"; string input = @"; v1.1.31.01'de tüm desktoplarda çalışır #NoEnv ; Uyumlukuk için A_ ön eki ile ortam değişkenlerini kullanın #SingleInstance Force ; Sadece 1 kez açalıştırabilire #KeyHistory 0 ; Tuş basımları loglamayı engeller SetBatchLines, -1 ; Scripti sürekli olarak çalıştırma (nromalde her saniye 10ms uyur) ListLines, Off ; Derlenen verileri loglamaz #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #MaxThreadsPerHotkey, 1 ; Yanlışlıkla 2 kere buton algılanmasını engeller VERSION = 1.2.0 ; Gizlenmiş pencelerin ID'si HidedWindows := [] ; TIP: Veri dizini yolu DIR_NAME = %A_AppData%\YHotkeys InstallIcons() CreateOrUpdateTrayMenu() return IconClicked: ToggleMemWindowWithTitle(A_ThisMenuItem) Return ClearAll: ClearAllHidedWindows() Return CloseApp: ClearAllHidedWindows() ExitApp Return class MenuObject { ahkID := 0 title := "" iconPath := "" } InstallIcons() { global DIR_NAME FileCreateDir, %DIR_NAME% FileInstall, .\res\seedling.ico, %DIR_NAME%\seedling.ico, 1 FileInstall, .\res\default.ico, %DIR_NAME%\default.ico, 1 FileInstall, .\res\clear.ico, %DIR_NAME%\clear.ico, 1 FileInstall, .\res\close.ico, %DIR_NAME%\close.ico, 1 } ClearAllHidedWindows() { ahkIDs := GetHidedWindowsIDs() For index, ahkID in ahkIDs { ToggleWindowWithID(ahkID, True) WinKill, ahk_id %ahkID% } } GetHidedWindowsIDs(){ ahkIDs := [] global HidedWindows For index, item in HidedWindows { ahkIDs.Push(item.ahkID) } return ahkIDs } GetHidedWindowsIDWithTitle(title){ global HidedWindows For index, item in HidedWindows { if (item.title == title) { return item.ahkID } } return 0 } GetHidedWindowsIndexWithID(ahkID){ global HidedWindows For index, item in HidedWindows { if (item.ahkID == ahkID) { return index } } return 0 } ToggleMemWindowWithTitle(menuName) { ahkID := GetHidedWindowsIDWithTitle(menuName) if ahkID ToggleWindowWithID(ahkID, True) else Run https://github.com/yedhrab/YHotkeys } RunUrl(url) { ; WARN: Bazı uygulamarın geç açılması soruna sebep oluyor ; BUG: Uygulamalar bazen 2 kere açılıyor try { SetTitleMatchMode, Slow RunWait, %url% } } ActivateWindowWithID(ahkID, wait=True) { WinActivate, ahk_id %ahkID% if wait WinWaitActive, ahk_id %ahkID% } ShowHidedWindowWithID(ahkId) { WinRestore, ahk_id %ahkID% WinShow, ahk_id %ahkID% } DropFromMem(ahkID){ index := GetHidedWindowsIndexWithID(ahkID) if index { global HidedWindows HidedWindows.RemoveAt(index) } return index } DropActiveWindowFromTrayMenu(){ WinGetTitle, title, A Menu, Tray, Delete, %title% global HidedWindows if !HidedWindows.Length() Menu, Tray, Delete, Temizle } DropActiveWindowFromMem(){ WinGet, ahkID, ID, A return DropFromMem(ahkID) } KeepInMem(ahkID, title, iconPath) { item := new MenuObject item.ahkID := ahkID item.title := title item.iconPath := iconPath global HidedWindows HidedWindows.Push(item) } ; Gizlenmeden önce kullanılmazsa id alamaz KeepActiveWindowInMem() { WinGetActiveTitle, title WinGet, ahkID, ID, A WinGet, iconPath, ProcessPath, A KeepInMem(ahkID, title, iconPath) } AddTrayMenuIcon(title, iconPath, default=True) { if FileExist(iconPath) { Menu, Tray, Icon, %title%, %iconPath%,, 20 } else if default { global DIR_NAME iconPath := DIR_NAME . ""\default.ico"" AddTrayMenuIcon(title, iconPath, False) } } CreateOrUpdateTrayMenu(){ #Persistent Menu, Tray, UseErrorLevel , On Menu, Tray, NoStandard Menu, Tray, Add, YHotkeys, IconClicked global VERSION Menu, Tray, Tip, YHotkeys v%VERSION% ~ YEmreAk Menu, Tray, Click, 1 global DIR_NAME iconPath := DIR_NAME . ""\seedling.ico"" if FileExist(iconPath) { Menu, Tray, Icon, %iconPath%,, 20 iconPath := DIR_NAME . ""\seedling.ico"" AddTrayMenuIcon(""YHotkeys"", iconPath) } global HidedWindows if (HidedWindows.Length() > 0) { Menu, Tray, Add, Temizle, ClearAll Menu, Tray, Delete, Temizle Menu, Tray, Delete, Kapat iconPath := HidedWindows[HidedWindows.Length()].iconPath mainTitle := HidedWindows[HidedWindows.Length()].title For index, item in HidedWindows { title := item.title iconPath := item.iconPath Menu, Tray, Add, %title%, IconClicked AddTrayMenuIcon(title, iconPath) } Menu, Tray, Add, Temizle, ClearAll iconPath := DIR_NAME . ""\clear.ico"" AddTrayMenuIcon(""Temizle"", iconPath) } else { mainTitle := ""YHotkeys"" } Menu, Tray, Default, YHotkeys Menu, Tray, Add, Kapat, CloseApp iconPath := DIR_NAME . ""\close.ico"" AddTrayMenuIcon(""Kapat"", iconPath) } SendWindowToTrayByID(ahkID) { WinHide ahk_id %ahkID% } ; WARN: Bug sebebi olabilir (bundan değil bug) ; WARN: Eğer uyarı mesajı verilirse, odaklanma bozuluyor FocusPreviusWindow(ahkID) { SendEvent, !{Esc} WinWaitNotActive, ahk_id %ahkID% } ToggleWindowWithID(ahkID, hide=False) { DetectHiddenWindows, Off if !WinExist(""ahk_id"" . ahkID) { if hide { ShowHidedWindowWithID(ahkID) ActivateWindowWithID(ahkID) if DropActiveWindowFromMem() DropActiveWindowFromTrayMenu() CreateOrUpdateTrayMenu() } else { ActivateWindowWithID(ahkID) } } else { if WinActive(""ahk_id"" . ahkID) { if hide { KeepActiveWindowInMem() FocusPreviusWindow(ahkID) SendWindowToTrayByID(ahkID) CreateOrUpdateTrayMenu() } else { WinMinimize, A } } else { ActivateWindowWithID(ahkID) } } } OpenWindowInTray(selector, name, url, mode=3) { SetTitleMatchMode, %mode% DetectHiddenWindows, On IDlist := [] if (selector == ""title"") { WinGet, IDlist, list, %name% } else if (selector == ""class"") { WinGet, IDlist, list, ahk_class %name% } else if (selector == ""exe"") { WinGet, IDlist, list, ahk_exe %name% } found := False Loop, %IDlist% { ahkID := IDlist%A_INDEX% if WinExist(""ahk_id"" . ahkID) { WinGetTitle, title if (title == "") continue ToggleWindowWithID(ahkID, True) found := True } } if !found RunUrl(url) } OpenWindowByTitle(title, url, mode=3) { SetTitleMatchMode, %mode% DetectHiddenWindows, Off if WinExist(title) { WinGet, ahkID, ID, %title% ToggleWindowWithID(ahkID, False) } else { RunUrl(url) } } GetEnvPath(envvar, path=""){ EnvGet, prepath, %envvar% path = %prepath%%path% return path } ; #################################################################################### ; ## ## ; ## KISAYOLLAR ## ; ## ## ; #################################################################################### ; ---------------------------------- Göster / Gizle ---------------------------------- #q:: name := ""- OneNote"" path := ""shell:appsFolder\Microsoft.Office.OneNote_8wekyb3d8bbwe!microsoft.onenoteim"" mode := 2 OpenWindowByTitle(name, path, mode) return ; #t:: ; name := ""Tureng Dictionary"" ; path := ""shell:appsFolder\24232AlperOzcetin.Tureng_9n2ce2f97t3e6!App"" ; mode := 2 ; OpenWindowByTitle(name, path, mode) ; return ; --------------------------------- Tray Kısayolları --------------------------------- #w:: ; WARN: 4 tane var exe ile ele alınmalı WhatsApp.exe (bundan değil) name := ""WhatsApp"" path := ""shell:appsFolder\5319275A.WhatsAppDesktop_cv1g1gvanyjgm!WhatsAppDesktop"" mode := 2 OpenWindowInTray(""title"", name, path, mode) return #g:: name := ""GitHub Desktop"" path := GetEnvPath(""localappdata"", ""\GitHubDesktop\GitHubDesktop.exe"") mode := 3 OpenWindowInTray(""title"", name, path, mode) return #x:: name := ""Google Calendar"" path := GetEnvPath(""appdata"", ""\Microsoft\Windows\Start Menu\Programs\Chrome Apps\Google Calendar.lnk"") mode := 2 OpenWindowInTray(""title"", name, path, mode) return #e:: name := ""CabinetWClass"" path := ""explorer.exe"" OpenWindowInTray(""class"", name, path) return ; Dizin kısayolları PgDn ile başlar PgDn & g:: name := ""GitHub"" path := GetEnvPath(""userprofile"", ""\Documents\GitHub"") OpenWindowInTray(""title"", name, path) return PgDn & s:: name := ""ShareX"" path := ""shell:appsFolder\19568ShareX.ShareX_egrzcvs15399j!ShareX"" mode := 3 OpenWindowInTray(""title"", name, path, mode) return PgDn & Shift:: name := ""Startup"" path := ""shell:startup"" mode := 3 OpenWindowInTray(""title"", name, path, mode) return PgDn & i:: name := ""Icons"" path := GetEnvPath(""userprofile"", ""\Google Drive\Pictures\Icons"") mode := 3 OpenWindowInTray(""title"", name, path, mode) return PgDn & d:: name := ""Downloads"" path := ""shell:downloads"" mode := 3 OpenWindowInTray(""title"", name, path, mode) return PgDn & u:: name := ""Yunus Emre Ak"" path := GetEnvPath(""userprofile"") mode := 3 OpenWindowInTray(""title"", name, path, mode) return ; --------------------------------- Buton Kısayolları --------------------------------- ; Değiştirilen butonları kurtarma Control & PgDn:: Send , !{PgDn} return Control & PgUp:: Send , !{PgUp} return "; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx