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

/
/
g

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/@((?:(?!@).)*)@((?:(?!@).)*)/'; $str = 'Define the term "affect"{The external expression of mood}Mood Disorders were previously known as:{Affective Disorders}True or False: Bipolar 1 disorder is one of the most genetically determined disorders in psychiatry.{True}In Bipolar 1 disorder, @[manic or depressive?]@ episodes predominate in @[youth]@.{Manic}In Bipolar 1 disorder, @[manic or depressive?]@ episodes predominate in @[later years]@.{Depressive}Another name for @anhedonia@ is @__________________ depression@{Endogenomorphic}What is the most consistent abnormality observed on CT/MRI in @depressive disorders@?{Increased frequency of abnormal hyperintensities in subcortical regions, especially the periventricular area, basal ganglia, and thalamus}The most consistent abnormality observed on CT/MRI in @depressive disorders@ are increased frequency of abnormal hyperintensities in subcortical regions, especially the:{- Periventricular area - Basal ganglia - Thalamus}Common side effects of Lithium include:{- GI disturbances - Nephrotoxicity - Hypothyroidism - Tremors - Leukocytosis - Acne - Psoriasis flares - Hair loss - Edema}Which laboratory tests should be obtained before starting patients on Lithium:{- TSH - Creatinine - Pregnancy test}What ratio of patients with acute depression will experience recurrences?{3/4}Serotonin neurons project from the brainstem dorsal raphe nuclei to the:{- Cerebral cortex - Hypothalamus - Thalamus - Basal ganglia - Septum - Hippocampus}Where do serotonin neurons project from?{Brainstem dorsal raphe nuclei}Acute stress @[increases or decreases]@ serotonin release{Increases}Chronic stress eventually _____________ serotonin stores{Depletes}Chronic stress may also increase synthesis of @[what serotonin autoreceptor?]@ in the dorsal raphe nucleus{5-HT 1A}Elevated glucocorticoid levels tend to @[enhance or reduce?]@ serotonergic functioning{Enhance @Thus, it may have significant compensatory effects on chronic stress}Double Depression is seen in approximately #-#% of patients with MDD{20-25%}Monozygotic twins have been shown to have a #-#x increase in concordance rates for mood disorders over dizygotic twins{2-4x}A @hypomanic episode@ lasts at least 4 days and is similar to a manic episode except that it is @not sufficiently severe enough to cause impairment in@:{Social or occupational functioning}The defense mechanism most commonly used in depression is:{Introjection}Nearly 2/3 of patients with depressive disorders exhibit marked shortening of:{REM latency}What is the term for mood elevation in response to something good happening?{Mood reactivity}What is the term for a heavy, leaden feelings in one\'s arms and legs?{Leaden paralysis}What is the amino acid precursor to serotonin?{Tryptophan}What is the amino acid precursor to dopamine?{Tyrosine}L-Tryptophan products were recalled in the U.S. because it was associated with:{Eosinophilia-myalgia syndrome}What is the term for depression that results from a specific life event?{Reactive depression}Reactive depression can be best compared to what disorder?{Adjustment disorder}Rapid cycling bipolar disorder is more common in Men or Women?{Women}Rapid cycling is defined as the occurance of #+ episodes of depression, hypomania, or mania per year{4+}The lifetime prevalence rate of cyclothymia is #-#%{0.4-1%}Which is more often present in depressed patients: psychomotor agitation or psychomotor retardation?{Psychomotor retardation}What is the term for the inability to describe or be aware of one\'s emotions or mood?{Alexithymia}The highest suicide rates are in what age group?{65+}Suicide is almost #x as frequent in older adults{2x}The suicide rate for Caucasian men age 65+ is #x higher than that of the general population.{5x}Aging @[increases/decreases]@ suicide attempts and @[increases/decreases]@ their lethality{Decreases; Increases}Schizoaffective Disorder AKA:{Cycloid psychosis}What are some medications that can precipitate mania?{- bromocriptine - isoniazide - cimetidine - disulfiram}Usually #-# ECT treatments are required to achieve symptomatic remission.{8-12}What is a common cognitive side effect of ECT?{Retrograde amnesia}What are the typical laboratory findings in NMS?{Leukocytosis and severely elevated CPK}True or False: Patients with anticholinergic delirium are more likely to be agitated than withdrawn.{True}Appropriate treatment (by the medical team) of NMS includes:{- Life support - Maintaining fluid and electrolyte balance - Decreasing fever}The treatment of NMS commonly combines what 2 medications?{bromocriptine & dantrolene}Which class of medication is particularly effective for the treatment of @atypical depression@?{MAOIs}What are 2 important side effects of MAOI therapy?{Hypertensive Crisis & Serotonin Syndrome}Hypertensive Crisis can be precipitated by eating foods rich in ________________.{Tyramine}Serotonin Syndrome is caused by the interaction of an MAOI with a ___________________.{SSRI, pseudoephedrine, or meperidine}True or False: Active SI is common in bereavement.{False}In what country is the diagnosis of @neurasthenia@ currently used the most?{China}What is the ICD-10 diagnosis for the following: "persistent and distressing complaints of increased fatigue after mental effort, or persistent and distressing complaints of bodily weakness and exhaustion after minimal effort"{Neurasthenia}What is a name for the condition that is the result of exhaustion of the CNS\'s energy reserves?{Neurasthenia}Neurasthenia is AKA:{Americanitis{https://o.quizlet.com/o5OIrToAmGoI.s2T15HuBQ_m.jpg} '; $subst = "<b>\1</b>\2"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$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 PHP, please visit: http://php.net/manual/en/ref.pcre.php