Regular Expressions 101

Save & Share

  • Regex Version: ver. 8
  • 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
No Match

r"
"
gum

Test String

Code Generator

Generated Code

use strict; my $str = 'Abbott A (1988) The System of Professions: An Essay on the Division of Expert Labor. Chicago, IL: University of Chicago Press. Albu OB and Flyverbom M (2016) Organizational transparency: conceptualizations, con- ditions, and consequences. Business & Society. Epub ahead of print 13 July. DOI: 10.1177/0007650316659851. Ananny M (2016) Toward an ethics of algorithms: convening, observation, probability, and timeli- ness. Science, Technology & Human Values 41(1): 93–117. DOI: 10.1177/0162243915606523. Anderson CW (2013) Towards a sociology of computational and algorithmic journalism. New Media & Society 15(7): 1005–1021. DOI: 10.1177/1461444812465137. Arnoldi J (2015) Computer algorithms, market manipulation and the institutionalization of high frequency trading. Theory, Culture & Society 33: 29–52. Bacon M (2012) Pragmatism. Cambridge: Polity Press. Baecker R (1998) Sorting out sorting: a case study of software visualization for teaching computer science. In: Stasko J (ed.) Software Visualization Programming as a Multimedia Experience. Cambridge, MA: The MIT Press, pp. 369–381. Ball C (2009) What is transparency? Public Integrity 11(4): 293–308. Barany MJ and MacKenzie D (2014) Chalk: materials and concepts in mathematics research. In: Coopmans C, Vertesi J, Lynch M, et al. (eds) Representation in Scientific Practice Revisited. Cambridge, MA: The MIT Press, pp. 107–130. Bateson G (2000) Steps to an Ecology of Mind: Collected Essays in Anthropology, Psychiatry, Evolution, and Epistemology. Chicago, IL: University of Chicago Press. Birchall C (2011) Introduction to “secrecy and transparency”: the politics of opacity and openness. Theory, Culture & Society 28(7–8): 7–25. Birchall C (2014) Radical transparency? Cultural Studies ↔ Critical Methodologies 14(1): 77–88. Bratich J (2016) Occult(ing) transparency: an epilogue. International Journal of Communication Systems 10: 178–181. Brill J (2015) Scalable approaches to transparency and accountability in decisionmaking algo- rithms: remarks at the NYU conference on algorithms and accountability. Federal Trade Commission, 28 February. Available at: https://www.ftc.gov/system/files/documents/pub- lic_statements/629681/150228nyualgorithms.pdf Brown MH (1998) A taxonomy of algorithm animation displays. In: Stasko J (ed.) Software Visualization Programming as a Multimedia Experience. Cambridge, MA: The MIT Press, pp. 35–42. Browne S (2015) Dark Matters: On the Surveillance of Blackness. Durham, NC: Duke University Press. Burrell J (2016) How the machine “thinks”: understanding opacity in machine learning algorithms. Big Data & Society 3(1). DOI: 10.1177/2053951715622512. Carusi A and Hoel AS (2014) Toward a new ontology of scientific vision. In: Coopmans C, Vertesi J, Lynch M, et al. (eds) Representation in Scientific Practice Revisited. Cambridge, MA: The MIT Press, pp. 201–221. Christensen LT and Cheney G (2015) Peering into transparency: challenging ideals, proxies, and organizational practices. Communication Theory 25(1): 70–90. Coddington M (2012) Defending a paradigm by patrolling a boundary: two global newspapers’ approach to WikiLeaks. Journalism & Mass Communication Quarterly 89(3): 377–396. Coleman G (2013) Coding Freedom: The Ethics and Aesthetics of Hacking. Princeton, NJ: Princeton University Press. Coopmans C, Vertesi J, Lynch M, et al. (2014) Introduction. In: Coopmans C, Vertesi J, Lynch M, et al. (eds) Representation in Scientific Practice Revisited. Cambridge, MA: The MIT Press, pp. 1–12. Crain M (2016) The limits of transparency: data brokers and commodification. New Media & Society. Epub ahead of print 7 July. DOI: 10.1177/1461444816657096. Crain W (2000) Theories and Development: Concepts and Applications. Upper Saddle River, NJ: Prentice Hall. Crary J (1990) Techniques of the Observer. Cambridge, MA: The MIT Press. Crawford K (2016) Can an algorithm be agonistic? Ten scenes from life in calculated publics. Science, Technology & Human Values 41(1): 77–92. da Vinci L (2015) Notebooks of Leonardo Da Vinci (trans. JP Richter). Istanbul: eKitap Projesi. Daston L (1992) Objectivity and the escape from perspective. Social Studies of Science 22(4): 597–618. Daston L and Galison P (2007) Objectivity. Brooklyn, NY: Zone Books. Datta A, Tschantz MC and Datta A (2015) Automated experiments on ad privacy settings. Proceedings on Privacy Enhancing Technologies 1: 92–112. David M (2015) The correspondence theory of truth. Stanford Encyclopedia of Philosophy, 28 May Available at: http://plato.stanford.edu/entries/truth-correspondence/ De Rijcke S and Beaulieu A (2014) Networked neuroscience: brain scans and visual knowing at the intersection of atlases and databases. In: Coopmans C, Vertesi J, Lynch M, et al. (eds) Representation in Scientific Practice Revisited. Cambridge, MA: The MIT Press, pp. 131– 152. Dewey J (1997) Experience and Education. New York: Free Press. Diakopoulos N (2016) Accountability in algorithmic decision making. Communications of the ACM 59(2): 56–62. DiSalvo C (2012) Adversarial Design. Cambridge, MA: The MIT Press. Dougherty C (2015) Google photos mistakenly labels black people “gorillas.” The New York Times, 1 July. Available at: http://bits.blogs.nytimes.com/2015/07/01/google-photos-mistak- enly-labels-black-people-gorillas/ Driscoll K and Walker S (2014) Working within a black box: transparency in the collection and production of big Twitter data. International Journal of Communication Systems 8: 1745–1764. Eslami M, Rickman A, Vaccaro K, et al. (2015) “I always assumed that I wasn’t really that close to [her]”: reasoning about invisible algorithms in the news feed. In: Proceedings of the 33rd annual ACM conference on human factors in computing systems, Seoul, Republic of Korea, 18–23 April. Flyverbom M (2016) Transparency: mediation and the management of visibilities. International Journal of Communication Systems 10: 110–122. Fox J (2007) The uncertain relationship between transparency and accountability. Development in Practice 17(4–5): 663–671. Fung A, Graham M and Weil D (2008) Full Disclosure: The Perils and Promise of Transparency. Cambridge: Cambridge University Press. Gillespie T (2014) The relevance of algorithms. In: Gillespie T, Boczkowski P and Foot KA (eds) Media Technologies: Essays on Communication, Materiality, and Society. Cambridge, MA: The MIT Press, pp. 167–194. Glasser TL (1989) Three views on accountability. In: Dennis EE, Gillmor DM and Glasser TL (eds) Media Freedom and Accountability. New York: Praeger. Goodwin C (1994) Professional vision. American Anthropologist 96(3): 606–633. Greenwald G (2014) No Place to Hide. New York: Metropolitan Books. Hallinan B and Striphas T (2014) Recommended for you: the Netflix Prize and the production of algorithmic culture. New Media & Society 18: 117–137. Hansen HK and Flyverbom M (2015) The politics of transparency and the calibration of knowl- edge in the digital age. Organization 22(6): 872–889. Heald D (2006) Varieties of transparency. Proceedings of the British Academy 135: 25–43. Heemsbergen L (2016) From radical transparency to radical disclosure: reconfiguring (in)vol- untary transparency through the management of visibilities. International Journal of Communication Systems 10: 138–151. Hilgartner S (2000) Science on Stage: Expert Advice as Public Drama. Stanford, CA: Stanford University Press. Hood C (2006) Transparency in historical perspective. In: Hood C and Heald D (eds) Transparency: The Key to Better Governance? Oxford: Oxford University Press, pp. 1–23. James W (1997) What pragmatism means. In: Menand L (ed.) Pragmatism: A Reader. New York: Random House, pp. 93–111. Kelty C (2008) Two Bits: The Cultural Significance of Free Software. Durham, NC: Duke University Press. Kushner S (2013) The freelance translation machine: algorithmic culture and the invisible indus- try. New Media & Society 15: 1241–1258. Leigh D and Harding L (2011) WikiLeaks: Inside Julian Assange’s War on Secrecy. New York: Public Affairs. Levy KEC (2015) The contexts of control: information, power, and truck-driving work. Information Society 31(2): 160–174. Levy KEC and Johns DM (2016) When open data is a Trojan Horse: the weaponization of trans- parency in science and governance. Big Data & Society 3(1). http://bds.sagepub.com/con- tent/3/1/2053951715621568 Lynch M and Woolgar S (1988) Introduction: sociological orientations to representational practice in science. Human Studies 11(2): 99–116. Mackenzie A (2015) The production of prediction: what does machine learning want? European Journal of Cultural Studies 18(4–5): 429–445. Mackenzie D (2008) An Engine, Not a Camera: How Financial Models Shape Markets. Cambridge, MA: The MIT Press. Michaels D (2008) Doubt Is Their Product: How Industry’s Assault on Science Threatens Your Health. Oxford: Oxford University Press. Minsky M (2007) The Emotion Machine: Commonsense Thinking, Artificial Intelligence, and the Future of the Human Mind. New York: Simon & Schuster. Misak C (ed.) (2007) New Pragmatists. Oxford: Oxford University Press. Napoli PM (2014) Automated media: an institutional theory perspective on algorithmic media production and consumption. Communication Theory 24(3): 340–360. Neyland D and Möllers N (2016) Algorithmic IF ... THEN rules and the conditions and conse- quences of power. Information, Communication & Society, 20 (1): 45-62. Papert S (1980) Mindstorms: Children, Computers, and Powerful Ideas. New York: Basic Books. Pasquale F (2015) The Black Box Society: The Secret Algorithms That Control Money and Information. Cambridge, MA: Harvard University Press. Phillips JWP (2011) Secrecy and transparency: an interview with Samuel Weber. Theory, Culture & Society 28(7–8): 158–172. Resnick M, Berg R and Eisenberg M (2000) Beyond black boxes: bringing transparency and aes- thetics back to scientific investigation. Journal of the Learning Sciences 9(1): 7–30. Schnackenberg AK and Tomlinson EC (2014) Organizational transparency: a new perspective on managing trust in organization-stakeholder relationships. Journal of Management 42: 1784–1810. Schrock AR (2016) Civic hacking as data activism and advocacy: a history from publicity to open government data. New Media & Society 18: 581–599. Schudson M (2015) The Rise of the Right to Know. Cambridge, MA: Belknap Publishing. Squires CR (2002) Rethinking the black public sphere: an alternative vocabulary for multiple public spheres. Communication Theory 12(4): 446–468. Stiny G (1980) Kindergarten grammars: designing with Froebel’s building gifts. Environment and Planning B 7(4): 409–462. Stohl C, Stohl M and Leonardi PM (2016) Managing opacity: information visibility and the para- dox of transparency in the digital age. International Journal of Communication Systems 10: 123–137. Striphas T (2015) Algorithmic culture. European Journal of Cultural Studies 18(4–5): 395–412. Tkacz N (2015) Wikipedia and the Politics of Openness. Chicago, IL: University of Chicago Press. Turner F (2006) From Counterculture to Cyberculture: Stewart Brand, the Whole Earth Network, and the Rise of Digital Utopianism. Chicago, IL: University of Chicago Press. Turner F (2013) The Democratic Surround. Chicago, IL: University of Chicago Press. Vertesi J (2014) Drawing as: distinctions and disambiguation in digital images of Mars. In: Coopmans C, Vertesi J, Lynch M, et al. (eds) Representation in Scientific Practice Revisited. Cambridge, MA: The MIT Press, pp. 15–36. Wade L (2010) HP software doesn’t see black people. Sociological Images, 5 January. Available at: https://thesocietypages.org/socimages/2010/01/05/hp-software-doesnt-see-black-people/ Ward SC (1996) Reconfiguring Truth. New York: Rowman & Littlefield. Zara C (2015) FTC chief technologist Ashkan Soltani on algorithmic transparency and the fight against biased bots. International Business Times, 9 April. Available at: http://www. ibtimes.com/ftc-chief-technologist-ashkan-soltani-algorithmic-transparency-fight-against- biased-1876177'; my $regex = qr/(([\w\s]+)\(([1|2]\d{3})\))(.*)/ump; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html