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

const regex = /\(https:\/\/en\.wikipedia\.org\/wiki[^)]*\)/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('\\(https:\\\/\\\/en\\.wikipedia\\.org\\\/wiki[^)]*\\)', 'gm') const str = `Couples **living apart together** (**LAT**) have an intimate relationship but live at separate addresses.[[1]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-1)[[2]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-2) It includes couples who wish to live together but are not yet able to, as well as couples who prefer to (or must) live apart, for various reasons. In the early ==2000s, LAT couples account for around 10% of adults in Britain== (excluding those who live with family), and over a quarter of all those not married or cohabiting. Similar figures are recorded for other countries in northern Europe, including Belgium, France, Germany, the Netherlands, Norway and Sweden.[[3]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-Living_Apart_Together:_A_New_Family-3)[[4]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-4) Research suggests similar or even higher rates in southern Europe, although there LAT couples often remain in parental households.[[5]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-People_who_live_apart_together_LAT-5) In Australia, Canada and the US representative surveys indicate that between 6% and 9% of unmarried adults has a partner who lives elsewhere.[[6]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-6)[[7]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-7)[[8]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-8) LAT is also increasingly understood and accepted publicly, is seen by most as good enough for partnering, and subject to the same expectations about commitment and fidelity as [marriage](https://en.wikipedia.org/wiki/Marriage "Marriage") or [cohabitation](https://en.wikipedia.org/wiki/Cohabitation "Cohabitation").[[5]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-People_who_live_apart_together_LAT-5) Within Asia, "[walking marriages](https://en.wikipedia.org/wiki/Walking_marriage "Walking marriage")" have been increasingly common in [Beijing](https://en.wikipedia.org/wiki/Beijing "Beijing"). Guo Jianmei, director of the center for women's studies at Beijing University, told a _[Newsday](https://en.wikipedia.org/wiki/Newsday "Newsday")_ correspondent, "Walking marriages reflect sweeping changes in Chinese society." A "walking marriage" refers to a type of temporary marriage formed by the [Mosuo](https://en.wikipedia.org/wiki/Mosuo "Mosuo") of China, in which male partners live elsewhere and make nightly visits.[[9]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-9) A similar arrangement in [Saudi Arabia](https://en.wikipedia.org/wiki/Saudi_Arabia "Saudi Arabia"), called [misyar marriage](https://en.wikipedia.org/wiki/Nikah_Misyar "Nikah Misyar"), also involves the husband and wife living separately but meeting regularly.[[10]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-10) ## Research Some researchers have seen living apart together as a historically new family form. From this perspective LAT couples can pursue both the intimacy of being in a couple and at the same time preserve autonomy.[[3]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-Living_Apart_Together:_A_New_Family-3) Some LAT couples may even de-prioritize couple relationships and place more importance on friendship.[[11]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-11) Alternatively, others see LAT as just a 'stage' on the way to possible cohabitation and marriage. In this view LATs are not radical pioneers moving beyond the family, rather they are cautious and conservative, and simply show a lack of commitment.[[12]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-Living-apart-together_in_Britain:_c-12) In addition many may simply be modern versions of 'steady' or long term boy/girlfriends.[[13]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-13) Research using more comprehensive data suggests LAT couples are a heterogeneous social category with varying motivations for living apart.[[5]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-People_who_live_apart_together_LAT-5) About a third see their relationship as too early for cohabitation, while others are prevented from living together, although they wish to do so, because of constraints like housing costs or (more rarely) job location. Many, however, prefer not to live together even though they have a long term relationship and could do so if they wanted. In practice motivations are often complex, for example one partner might wish to preserve the family home for existing children while the other might welcome autonomous time and space. Sometimes 'preference' can have a defensive motivation, for example the emotional desire to avoid the recurrence of a failed or unpleasant cohabiting relationship. Overall, LAT couples may be 'gladly apart; 'regretfully apart' or, for many, undecided and ambivalent where they experience both advantages and disadvantages.[[14]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-14) ## Demographics People living apart from their partner can be found in all age groups, although they are on average younger than cohabiting and married couples.[[12]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-Living-apart-together_in_Britain:_c-12)[[15]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-15) In Britain almost 50% of LAT couples are in the youngest age group (18–24) although significant proportions are found in the 25–55 age group. Non-parents (those without current dependent children) are significantly more likely than parents to live apart from their partner. LAT couples are also found in all socio-economic groups, and in Britain show little difference to the class profile of the population as a whole. ## In the life course Living in LAT relationships means different things at different stages of the life course. Many LAT relationships among young adults and among adults with co-resident, dependent children are temporary and involuntary.[[16]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-Connidis_et_al-16) However, Living Apart Together in Later Life (LLAT) are generally a stable alternative to living with a partner.[[16]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-Connidis_et_al-16) Among older persons, priorities shift as the responsibilities of raising children and paid work diminish and a limited future increases a preference for effectively rich relationships. LLAT is well suited to this process. The low level of organization of LLAT relationships and the absence of many of the commitments and ties that characterize marriage put the focus on the emotional side of the relationship.[[17]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-17) Gender also shapes the appeal of LLAT. Swedish research showed that older women were significantly more motivated to live apart together to secure independence and avoid a traditional gendered division of labor.[[18]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-18) ## Attitudes Living apart as a couple is increasingly understood and accepted. By 2006, in Britain, a majority (54 per cent) agreed that "a couple do not need to live together to have a strong relationship", with only 25 per cent disagreeing.[[19]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-19) By 2000 about one fifth of people aged 16–44 in Britain described 'living together apart' as their 'ideal relationship', compared to over 40 per cent for exclusive marriage and just under 20 per cent for unmarried cohabitation.[[20]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-20) Attitudinally, LATs couples themselves resemble cohabitants in a 'young partners' group, as opposed to a more conservative 'older married' majority.[[21]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-21) Controlling for age LATs appear to be somewhat more liberal than other relationship categories for issues that directly affect them, for example about the effect of independence in relationships. However, for other controversial 'family' issues (like acceptance of same-sex partnership or of single motherhood) being a LAT in itself makes little difference, rather it is the relative traditionality of older married people that stands out compared to generally younger, and more liberal, unmarried cohabitants and LAT couples. ## Examples of couples Famous and celebrity couples have been cited from the 19th century to the 21st century. For example, a 2007 _Times_ article[[22]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-22) names [Woody Allen](https://en.wikipedia.org/wiki/Woody_Allen "Woody Allen") and [Mia Farrow](https://en.wikipedia.org/wiki/Mia_Farrow "Mia Farrow") (then living either side of [Central Park](https://en.wikipedia.org/wiki/Central_Park "Central Park"), [New York City](https://en.wikipedia.org/wiki/New_York_City "New York City")), [Margaret Drabble](https://en.wikipedia.org/wiki/Margaret_Drabble "Margaret Drabble") and [Michael Holroyd](https://en.wikipedia.org/wiki/Michael_Holroyd "Michael Holroyd") (married 36 years as of 2018, separate homes), [Helena Bonham Carter](https://en.wikipedia.org/wiki/Helena_Bonham_Carter "Helena Bonham Carter") and [Tim Burton](https://en.wikipedia.org/wiki/Tim_Burton "Tim Burton") and their two children (two houses next door to each other in [Hampstead](https://en.wikipedia.org/wiki/Hampstead "Hampstead"), [London](https://en.wikipedia.org/wiki/London "London")), and [Booker prizewinner](https://en.wikipedia.org/wiki/Booker_prize "Booker prize") [Arundhati Roy](https://en.wikipedia.org/wiki/Arundhati_Roy "Arundhati Roy") and husband [Pradip Krishen](https://en.wikipedia.org/wiki/Pradip_Krishen "Pradip Krishen") (with separate homes in [Delhi](https://en.wikipedia.org/wiki/Delhi "Delhi"), [India](https://en.wikipedia.org/wiki/India "India")). In the 1840s, the famous composer [Frédéric Chopin](https://en.wikipedia.org/wiki/Fr%C3%A9d%C3%A9ric_Chopin "Frédéric Chopin") and the female novelist [George Sand](https://en.wikipedia.org/wiki/George_Sand "George Sand") had an "unusual" relation that would be called LAT nowadays. The LAT relationship between philosopher [Jean-Paul Sartre](https://en.wikipedia.org/wiki/Jean-Paul_Sartre "Jean-Paul Sartre") (1905–1980) and the feminist writer [Simone de Beauvoir](https://en.wikipedia.org/wiki/Simone_de_Beauvoir "Simone de Beauvoir") (1908–1986) is often cited (although was exceptional in that Sartre apparently had other contemporaneous, if temporary, liaisons). It is important to remember, however, that it is not just the rich and famous who live apart together, LAT is common amongst ordinary people in all social groups. The documentary _Two's a Crowd_ documents a New York City couple that was forced to give up a LAT relationship because of the economic downturn of the late 2000s. The film depicts how the couple tries to set up two separate "apartments" within one, after they are forced to move in with each other.[[23]](https://en.wikipedia.org/wiki/Living_apart_together#cite_note-23)`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions