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
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"^(?<author>[A-Z](?:(?!$)[A-Za-z\s&.,'’])+)\((?<year>\d{4})\)\.?\s*(?<title>[^()]+?[?.!])\s*(?:(?:(?<jurnal>(?:(?!^[A-Z])[^.]+?)),\s*(?<issue>\d+)[^,.]*(?=,\s*\d+|.\s*Ret))|(?:In\s*(?<editors>[^()]+))\(Eds?\.\),\s*(?<book>[^().]+)|(?:[^():]+:[^().]+\.)|(?:Retrieved|Paper presented))", flags=re.MULTILINE) test_str = ("\n\n" "Anonymous. (1998). To reveal or not to reveal: A theoretical model of anonymous\n" " communication. Communication Theory, 8, 381–407.\n\n" "Bailenson, J. (2006). Transformed social interaction in collaborative virtual environments.\n" " In P. Messaris & L. Humphreys (Eds.), Digital media: Transformations in human\n" " communication (pp. 255–264). New York: Peter Lang.\n\n" "Bailenson, J., Beall, A., Blascovich, J., Loomis, J., & Turk, M. (2005). Transformed social\n" " interaction, augmented gaze, and social influence in immersive virtual environments.\n" " Human Communication Research, 31, 511–537.\n\n" "Bailenson, J., Blascovich, J., Beall, A., & Loomis, J. (2003). Interpersonal distance in immersive\n" " virtual environments. Personality and Social Psychology Bulletin, 29, 1–15.\n" "Bem, D. (1972). Self perception theory. In L. Berkowitz (Ed.), Advances in experimental social\n\n" " psychology (Vol. 6). New York: Academic Press.\n" "Blascovich, J., Loomis, J., Beall, A., Swinth, K., Hoyt, C., & Bailenson, J. (2002). Immersive\n" " virtual environment technology as a methodological tool for social psychology.\n\n" " Psychological Inquiry, 13(2), 103–124.\n" "Burgoon, J. (1978). A communication model of personal space violation: Explication and an\n" " initial test. Human Communication Research, 4, 129–142.\n\n" "Burgoon, J., & Walther, J. (1990). Nonverbal expectancies and the evaluative consequences of\n" " violations. Human Communication Research, 17, 232–265.\n" "Burgoon, J., Walther, J., & Baesler, E. (1992). Interpretations, evaluations, and consequences\n\n" " of interpersonal touch. Human Communication Research, 19, 237–263.\n" "Chan, E., & Vorderer, P. (2006). Massively multiplayer online games. In P. Vorderer &\n" " J. Bryant (Eds.), Playing computer games—Motives, responses, and consequences. Mahwah,\n\n" " NJ: Lawrence Erlbaum.\n" "Culnan, M. J., & Markus, M. L. (1987). Information technologies. In F. M. Jablin &\n" " L. L. Putnam (Eds.), Handbook of organizational communication: An interdisciplinary\n\n" " perspective (pp. 420–443). Thousand Oaks, CA: Sage Publications.\n" "Dion, K., Berscheid, E., & Walster, E. (1972). What is beautiful is good. Journal of Personality\n" " and Social Psychology, 24, 285–290.\n\n" "Flanagin, A. J., Tiyaamornwong, V., O’Connor, J., & Seibold, D. R. (2002).\n" " Computer-mediated group work: The interaction of member sex and anonymity.\n\n" " Communication Research, 29, 66–93.\n" "Forsythe, R., Horowitz, J., Savin, N., & Sefton, M. (1994). Fairness in simple bargaining\n" " experiments. Games and Economic Behavior, 6, 347–369.\n\n" "Frank, M., & Gilovich, T. (1988). The dark side of self and social perception: Black uniforms\n" " and aggression in professional sports. Journal of Personality and Social Psychology, 54,\n" " 74–85.\n\n" "Freedman, D. G. (1979). Human sociobiology. New York: Free Press.\n\n\n" "288 Human Communication Research 33 (2007) 271–290 ª 2007 International Communication Association\n" "N. Yee & J. Bailenson The Proteus Effect\n\n" "Friend, R. M., & Vinson, M. (1974). Leaning over backward: Jurors responses to defendants’\n\n" " attractiveness. Journal of Communication, 24, 124–129.\n" "Gergen, K., Gergen, M., & Barton, W. H. (1973). Deviance in the dark. Psychology Today,\n" " 11, 129–130.\n\n" "Hancock, J., & Dunham, P. (2001). Impression formation in computer-mediated\n" " communication revisited: An analysis of the breadth and intensity of impressions.\n" " Communication Research, 28, 325–347.\n\n" "Harrison, A. A., & Saeed, L. (1977). Let’s make a deal: An analysis of revelations and\n" " stipulations in lonely hearts advertisements. Journal of Personality and Social Psychology,\n" " 35, 257–264.\n\n" "Hiltz, S., Johnson, K., & Turoff, M. (1986). Experiments in group decision making:\n" " Communication processes and outcome in face-to-face versus computerized conferences.\n" " Human Communication Research, 13, 225–252.\n\n" "Jacobson, D. (1999). Impression formation in cyberspace: Online expectations and offline\n" " experiences in text-based virtual communities. Journal of Computer-Mediated\n\n" " Communication, 5. Retrieved April 26, 2007, from http://jcmc.indiana.edu/vol5/issue1/\n" " jacobson.html\n" "Jarvenpaa, S., & Leidner, D. (1998). Communication and trust in global virtual teams. Journal\n\n" " of Computer-Mediated Communication, 3. Retrieved April 26, 2007, from http://\n" " jcmc.indiana.edu/vol3/issue4/jarvenpaa.html\n" "Johnson, R., & Downing, L. (1979). Deindividuation and valence of cues: Effects on prosocial\n\n" " and antisocial behavior. Journal of Personality and Social Psychology, 37, 1532–1538.\n" "Kiesler, S., Siegel, J., & McGuire, T. W. (1984). Social psychological aspects of\n" " computer-mediated communication. American Psychologist, 39, 1123–1134.\n\n" "Langlois, J., Kalakanis, L., Rubenstein, A., Larson, A., Hallam, M., & Smoot, M. (2000).\n" " Maxims or myths of beauty?: A meta-analytic and theoretical review. Psychological\n" " Bulletin, 126, 390–423.\n\n" "Lea, M., O’Shea, T., & Spears, R. (1992). ‘‘Flaming’’ in computer-mediated communication.\n" " In M. Lea (Ed.), Contexts of computer-mediated communication (pp. 89–112). New York:\n" " Harvester Wheatsheaf.\n\n" "Linden Labs (2006). What is second life? Retrieved May 5, 2006, from lindenlab.com/\n" " ProductFactSheet.pdf\n" "Loomis, J., Blascovich, J., & Beall, A. (1999). Immersive virtual environments as a basic\n\n" " research tool in psychology. Behavior Research Methods, Instruments, and Computers,\n" " 31, 557–564.\n" "McKenna, K., & Bargh, J. (2000). Plan 9 from cyberspace: The implications of the Internet for\n\n" " personality and social psychology. Personality and Social Psychology Review, 4, 57–75.\n" "Merola, N., Penas, J., & Hancock, J. (2006). Avatar color and social identity effects: On attitudes\n" " andgroupdynamics invirtualrealities. Paper presented at the ICA 2006, Dresden, Germany.\n\n" "National Center for Health Statistics (2004). National health and nutrition examination\n" " survey 2003-2004. Retrieved September 5, 2006, from http://www.cdc.gov/nchs/about/\n" " major/nhanes/nhanes2003-2004/nhanes03_04.htm\n\n" "Normand, V., Babski, C., Benford, S., Bullock, A., Carion, S., Chrysanthou, Y, et al. (1999).\n" " The COVEN project: Exploring applicative, technical, and usage dimensions of\n\n" " collaborative virtual environment. Presence: Teleoperators and Virtual Environments, 8,\n" " 218–236.\n\n\n\n" "Human Communication Research 33 (2007) 271–290 ª 2007 International Communication Associati289\n" "The Proteus Effect N. Yee & J. Bailenson\n\n" "Parks, M. R., & Floyd, K. (1996). Making friends in cyberspace. Journal of Communication,\n\n" " 46, 80–96.\n" "Postmes, T., & Spears, R. (2002). Behavior online: Does anonymous computer\n" " communication reduce gender inequality? Personality & Social Psychology Bulletin, 28,\n\n" " 1073–1083.\n" "Postmes, T., Spears, R., & Lea, M. (1998). Breaching or building social boundaries?\n" " Communication Research, 25, 689–699.\n\n" "Postmes, T., Spears, R., & Lea, M. (2000). The formation of group norms in\n" " computer-mediated communication. Human Communication Research, 26, 341–371.\n" "Short, J., Williams, E., & Christie, B. (1976). The social psychology of telecommunications.\n\n" " London: Wiley.\n" "Snyder, M., Tanke, E. D., & Berscheid, E. (1977). Social perception and interpersonal\n" " behavior: On the self-fulfilling nature of social stereotypes. Journal of Personality & Social\n\n" " Psychology, 35, 656–666.\n" "Spears, R., & Lea, M. (1994). Panacea or panopticon? The hidden power in\n\n" " computer-mediated communication. Communication Research, 21, 427–459.\n" "Stogdill, R. M. (1948). Personal factors associated with leadership: A survey of the literature.\n" " Journal of Psychology, 25, 35–71.\n\n" "Trevino, L., & Webster, J. (1992). Flow in computer-mediated communication: electronic\n" " mail and voice mail evaluation and impacts. Communication Research, 19, 539–573.\n" "Turkle, S. (1995). Life on the screen: Identity in the age of the Internet: New York: Simon and\n\n" " Schuster.\n" "Valins, S. (1966). Cognitive effects of false heart-rate feedback. Journal of Personality and\n" " Social Psychology, 4, 400–408.\n\n" "Walther, J. (1996). Computer-mediated communication: Impersonal, interpersonal, and\n" " hyperpersonal interaction. Communication Research, 23(1), 3–43.\n" "Walther, J., Anderson, J., & Park, D. (1994). Interpersonal effects in computer-mediated\n\n" " interaction: A meta-analysis of social and anti-social communication. Communication\n" " Research, 21, 460–487.\n" "Walther, J., Slovacek, C., & Tidwell, L. (2001). Is a picture worth a thousand words?:\n\n" " Photographic images in long-term and short-term computer-mediated communication.\n" " Communication Research, 28, 105–134.\n" "Yee, N. (2006). The demographics, motivations, and derived experiences of users of massively\n\n" " multi-user online graphical environments. Presence: Teleoperators and Virtual\n" " Environments, 15, 309–329.\n" "Young, T. J., & French, L. A. (1996). Height and perceived competence of U.S. Presidents.\n\n" " Perceptual and Motor Skills, 82, 1002.\n" "Zimbardo, P. (1969). The human choice: Individuation, reason, and order vs.\n" " deindividuation, impulse and chaos. In W. J. Arnold & D. Levine (Eds.), Nebraska\n\n" " symposium on motivation (Vol. 17, pp. 237–307). Lincoln: University of Nebraska Press.\n\n\n\n\n\n\n\n\n\n\n\n" "290 Human Communication Research 33 (2007) 271–290 ª 2007 International Communication Association\n") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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