Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
g

Test String

Code Generator

Generated Code

$re = '/<ref>(?:(?:\s)*https?:\/\/)?(?:www\.)?(?:\s)*?twitter\.com\/(?:#!\/)?@?([^\/\?\s]*)\/status\/([{\d+:\d+\}]*)(?:[^\<]+)?/'; $str = '{{Use dmy dates|date=February 2013}} {{Use British English|date=February 2013}} {{Infobox road |country=GBR |type=A |route=477 |image =A477 trunk road from the bridge - geograph.org.uk - 1404312.jpg |image_notes=The A477 near [[Kilgetty]] |length_mi =27.8 |length_ref =<ref>{{cite web |url=https://maps.google.co.uk/maps?saddr=A477,+St+Clears,+Carmarthenshire+SA33,+UK&daddr=51.7534814,-4.6778932+to:A477&hl=en&ll=51.775913,-4.774933&spn=0.238768,0.620728&sll=51.750096,-5.000979&sspn=0.003733,0.009699&geocode=FeukFgMd00G7_ymlDAOQrttuSDHv6MO8BQzrjw%3BFQmyFQMd-564_ykzl6T6881uSDHhH3HfTLunTQ%3BFWWnFQMdgq6z_w&t=h&mra=mift&mrsp=1&sz=17&z=11&via=1 |title=Directions to A477 |last1= |first1= |last2= |first2= |date= |work= |publisher=[[Google]] |accessdate=14 April 2013}}</ref> |direction_a= East |terminus_a = [[St Clears]]<br>{{coord|51.8163|-4.5049|type:landmark_region:GB|display=inline|name=A477 road (eastern end)}} |direction_b= West |terminus_b = [[Johnston, Pembrokeshire|Johnston]]<br>{{coord|51.7508|-5.0016|type:landmark_region:GB|display=inline|name=A477 road (western end)}} |junction = {{ukroadsmall|40}}<br />{{ukroadsmall|478}}<br />{{gbroadsmall|4075}}<br />{{gbroadsmall|4076}} |destinations= <br />[[St Clears]]<br/>[[Pembroke Dock]] }} The \'\'\'A477\'\'\' is a major road in [[Pembrokeshire|South Pembrokeshire]] and [[Carmarthenshire]] connecting [[St Clears]] and [[Johnston, Pembrokeshire|Johnston]]. Its route includes the [[Cleddau Bridge]], a [[toll bridge]] linking [[Pembroke Dock]] and [[Neyland]]. From the [[A40 road (Great Britain)|A40]] in St Clears, the A477 is a trunk road with primary status as far as the Waterloo roundabout in Nash, Pembroke Dock, on the south-east side of the [[Milford Haven Waterway]]. Responsibility for the management and maintenance of this section lies with the South Wales Trunk Road Agency, on behalf of the [[Welsh Assembly Government]]. From there the responsibility for maintaining the A477 is held by [[Pembrokeshire County Council]]. ==History== [[File:New A477 Red Roses By Pass - looking west-geograph-3928687-by-welshbabe.jpg|thumb|left|Red Roses bypass - looking west]] A route from St Clears to Pembroke Dock was first surveyed by [[Thomas Telford]] in 1826, as part of a review of the route of the mail service from London to Ireland that at the time went via the docks at Milford Haven. A decision was taken in 1827 to move the mail port from Milford Haven to Hobbs Point in Pembroke Dock, and to pursue the access route from St Clears to Pembroke Dock. By 1830, a section of the road between the villages of [[Llanddowror]] and [[Red Roses]] had been completed.<ref name="Ayres2011">{{cite book |last=Ayres |first=George |date=2011 |title=History of the Mail Routes to Ireland Until 1850 |page=64-65 |isbn=9781446605042}}</ref> A levy on mail passing through Milford was introduced by the Postage Act 1836, to be used to fund the new route.<ref>{{cite act | title = Postage Act 1836 | number = 6 Will 4 c.25 | language = English | date = {{date|1836-06-21|mdy}}}}</ref> The full route was completed in 1839, running from St Clears via Llanddowror, Red Roses, [[Llanteg]], [[Begelly]] and [[Carew, Pembrokeshire|Carew]] to Pembroke Dock.<ref name="Ayres2011" /> [[File:A477Road 1923MOTMap.png|thumb|Original route of the A477 road in 1923 between Pembroke Dock and Red Roses]] Road designations were first allocated by the [[Ministry of Transport]] in 1922 with the road between Red Roses and Pembroke Dock being designated the A477. The section between St Clears and Red Roses had been part of the A40 until the early 1930s. The 22-mile section of the road from its start at St Clears as far as Nash{{mdash}}which is a convenient distribution point for places on the south side of Milford Haven{{mdash}}was promoted to a [[Trunk road#United Kingdom|trunk road]] following an announcement by the (then) [[Secretary of State for Wales]], [[Cledwyn Hughes]], on 14 November 1966.<ref>{{cite web |title=Wales (Trade and Industry) House of Commons debates |date=1966-11-14 |url=https://www.theyworkforyou.com/debate/?id=1966-11-14a.40.3}}</ref> The Kilgetty-Begelly bypass was completed in 1984 at a cost of £14.2 million.<ref>{{cite web |url=http://hansard.millbanksystems.com/written_answers/1990/apr/24/road-improvements-pembroke#S6CV0171P0_19900424_CWA_216 |title=Road Improvements, Pembroke House of Commons Written Answers |date=1990-04-24}}</ref> The Sageston-Redberth bypass was completed in 2002 at a cost of £6.4 million.<ref>{{cite web |url=http://cymru.gov.uk/news/archivepress/environmentpress/enviropress2002/750626/?lang=en |title=Completion of A477 Sageston - Redberth bypass welcomed by Sue Essex |date=2002-09-25}}</ref> A new bypass improvement scheme for the section of the A477 between [[St Clears]] and [[Red Roses]] was approved by the Welsh Government on 27 January 2012. Construction work on the new bypass began in mid 2012.<ref>[http://www.a477stclearsredroses.com A477 Red Roses St Clears Improvement Scheme]</ref> Constructed with a straighter alignment and bypassing the villages of Red Roses and [[Llanddowror]], the new section was scheduled to open during May 2014<ref>https://twitter.com/A477SCRR/status/423121289952251904/photo/1?test4334/</ref> but opened to general traffic at around 12:25 pm on 16 April 2014 having previously been declared open earlier in the day by [[Edwina Hart]], Welsh Assembly Member for Transport.<ref>{{cite news|url=http://www.itv.com/news/wales/story/2014-04-15/section-of-a477-to-officially-open-after-68m-upgrade |title=Section of A477 officially opens after £68m upgrade |work=ITV News Wales |date=16 April 2014 |accessdate=17 April 2014 |archiveurl=https://web.archive.org/web/20140417140930/http://www.itv.com/news/wales/story/2014-04-15/section-of-a477-to-officially-open-after-68m-upgrade |archivedate=17 April 2014 |deadurl=yes |df= }}</ref><ref>{{cite web|url=http://wales.gov.uk/newsroom/transport/2014/140416A477/?lang=en |work=Welsh Government News |title=£68million improvements to A477 brings benefits to the economy, tourism and local communities |date=16 April 2014 |accessdate=17 April 2014 |deadurl=yes |archiveurl=https://web.archive.org/web/20140417024513/http://wales.gov.uk/newsroom/transport/2014/140416A477/?lang=en |archivedate=17 April 2014 |df= }}</ref> ==Route== From east to west, it runs either through, near or over: * [[St Clears]] * over the [[River Taf]] * [[Llanddowror]] * [[Red Roses]] * [[Llanteg]] * [[Kilgetty]] * Redberth * Sageston * [[Carew, Pembrokeshire|Carew]] * Milton * Slade Cross * [[Pembroke Dock]] * over the [[Cleddau Bridge]] * [[Neyland]] * [[Johnston, Pembrokeshire|Johnston]]. The A477 is {{convert|27.8|mi|km}} in length. ==See also== *[[British road numbering scheme]] *[[Trunk roads in Wales]] ==References== {{reflist}} ==External links== {{GeoGroupTemplate}} * {{commonscat-inline|A477 road (Wales)}} *[https://archive.is/20070813201755/http://www.uk-roads.org.uk/roadlists/r10/notes.php?number=A477 A477 at SABRE] {{GB A road zone 4}} {{Motorways and Trunk Roads in Wales|state=collapsed}} {{Transport in Carmarthenshire}} {{Transport in Pembrokeshire}} {{Portal bar|Roads|Wales}} {{coord|51.7214|-4.7496|dim:20000_region:GB|display=title|name=A477 road}} {{DEFAULTSORT:4-0477}} [[Category:Roads in Carmarthenshire]] [[Category:Roads in Pembrokeshire]] '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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