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

/
/
ug

Test String

Code Generator

Generated Code

import Foundation // WARNING: You included a flag that Swift doesn't support: u // When this flag is set, it makes the pattern and subject strings to be treated as unicode. // Swift already treats the pattern and subject strings as unicode by default, so including this flag is redundant. let pattern = #"(?:^|\n)([^?;1-9\n]*)(?:\.|,)*\s(\(*\d+\)*)(?:,|\.)(.*)"# let regex = try! NSRegularExpression(pattern: pattern) let testString = #""" Albayrak, İ. 2012. Ekosistem servislerine dayalı havza yönetim modelinin İstanbul-Ömerli havzası örneğinde uygulanabilirliği, Doktora Tezi, İTÜ Fen Bilimleri Enstitüsü. Agren, C. 1991. EMEP report, MCS-W 1/91 Norway. Ahern, J., Cilliers, S. and Niemela, J. 2014. The concept of ecosystem services in adaptive urban planning and design: a framework for supporting innovation, Landscape and Urban Planning, 125: 254–259. http://dx.doi.org/10.1016/j.landurbplan.2014.01.020 Aygün, M ve Yeşil Akça, G. 2012. T.C. Orman ve Su İşleri Bakanlığı bakanlığımız ve bağlı kuruluşlarınca yürütülen Ar-Ge nitelikli projeler, www.milliparklar.gov.tr/korunanalanlar/belgeler/tescil.pdf, Erişim: 21 Şubat 2016. Balkız, Ö. 2015. Ekosistem hizmetleri ve havza yönetimi, http://suyonetimi.ormansu.gov.tr/Libraries/su/EkosistemHizmetleri_OzgeBalkiz_20151216.sflb.ashx, Erişim: 21 Şubat 2016. Bassett, C.G. 2015. The environmental benefits of trees on an urban university campus, Master of Environmental Studies Capstone Projects. 66. p. Bloniarz, D. and Beals, T. 2014. I-tree canopy assessment to Springfield MA, http://www.regreenspringfield.org/, Accessed July, 20, 2016. Bolund, P. and Hunhammar, S. 1999. Ecosystem services in urban areas, Ecological Economics, 29: 293–301. Brack, C.L. 2002. Pollution mitigation and carbon sequestration by an urban forest. Environmental Pollution, 116:195– 200. Carey, B. and Tobin, B. 2016. Ecosystem services provided by mountshannon village trees, https://static.rasset.ie/documents/ radio1/mountshannon-ecosystem-services-provided-by-mountshannon-village-june-2016.pdf, Erişim 20 Temmuz 2016. Chaparro, L. and Terradas, J. 2009. Ecological services of urban forest in Barcelona. Centre de Recerca Ecologica i Aplicacions Forestals, p. 103. Coşkun Hepcan, Ç., Özeren, M. ve Hepcan, Ş. 2013. İzmir için ekolojik açıdan sürdürülebilir bir kent gelişim senaryosu, TMMOB İzmir 2. Kent Sempozyumu Bildiriler Kitabı, TMMOB İzmir 2. Kent Sempozyumu Bildiriler Kitabı - Kentine Sahip Çık, 28- 30 Kasım 2013: 803-811. Curtis, L., Rea, W., Smith-Willis, P., Fenyves, E. and Pan, Y. 2006. Adverse health effects of outdoor in pollutants, Environmental International, 32: 815-830. Çevre ve Şehircilik Bakanlığı, 2014. Yer seviyesi ozon kirliliği bilgi notu, T.C. Çevre ve Şehircilik Bakanlığı Çevre Yönetimi Genel Müdürlüğü, s.3. Çevre ve Şehircilik Bakanlığı, 2016. Çevre ve Şehircilik Bakanlığı hava kalitesi izleme istasyonları web sitesi, http://www.havaizleme.gov.tr/hava.html, Erişim 20 Temmuz 2016. Derkzen, M.L., Van Teeffelen, A.J.A. and Verburg, P.H. 2015. Quantifying urban ecosystem services based on highresolution data of urban green space: an assessment for Rotterdam, the Netherlands, Journal of Applied Ecology, 52: 1020–1032. Forman, R.T.T. 2008. Urban regions: ecology and planning beyond the city, NY Cambridge University Press, p. 408. ISBN-13: 978-0521670760. Forman, R.T.T. 2014. Urban ecology science of cities, Cambridge University Press, p. 462. ISBN-13: 978-052118824. Gomez-Baggethun, E. and Barton, D.N. 2013. Classifying and valuing ecosystem services for urban planning, Ecological Economics, 86: 235-245. Güvendik G. ve Yılmaz A. 2003. Egzos kirliliğine maruz kalan kişilerde kan karboksihemoglobin düzeyi. Ankara Eczacılık Fakültesi Dergisi, 32: 213-219. Hepcan, Ş. 2013. Analyzing the pattern and connectivity of urban green spaces: a case study of Izmir, Turkey, Urban Ecosystems, 16: 279–293, DOI:10.1007/s11252-012-0271-2. Hutchings, T., Lawrence, V. and Brunt, A. 2012. Estimating the ecosystem services value of Edinburgh’s trees, The Research Agency of Forest Commission, p. 45. Kardeşoğlu E., Yalçın M. ve Işılak Z., 2011. Hava kirliliği ve kardiyovasküler sistem. TAF Preventive Medicine Bulletin, 10: 97-106. Marcus, C. 2015. Tree canopy assessment city of Atlantic Beach Florida, Legacy Arborist Services Tallahassee, FL, p. 8. MEA (Millennium Ecosystem Assessment). 2005. Ecosystems and human well- being: a framework for assessment. MA (Millennium Ecosystem Assessment). http://www.millenniumassessment.org/ en/Framework.html. Moran, J.M. and Mogan, M.D. 1994. Meterology: the atmosphere and the science of weather, NY Macmillan College Publishing Company. McNeil, J. and Vava, C. 2006. Oakville's urban forest: our solution to pollution, Town of Oakville Parks and Open Space Department Forestry Section, p. 67. Nowak, D.J. 2000. The interactions between urban forests and global climate change. In: Abdollahi KK, Ning ZH, Appeaning A (eds) Global change and urban forest. GCRCC and Franklin Press, Baton Rouge, LA, pp. 31–44. Nowak, D.J., Hoehn, R.E., Bodine, A.R., Crane, D.E., Dwyer, J.F., Bonnewell, V. and Watson, G. 2013. Urban trees and forests of the Chicago region. Resour. Bull. NRS-84. Newtown Square, PA: U.S. Department of Agriculture, Forest Service, Northern Research Station. p 106. Jacobs, B., Mikhailovich, N. and Delaney, C. 2014. Benchmarking Australia’s urban tree canopy: an ı-tree assessment, prepared for horticulture Australia limited by the Institute for Sustainable Futures, University of Technology Sydney, final-report_140930.pdf, p. 49. Phillips, D., Burdick, C., Merja, B. and Brown. N. 2013. Urban forest ecosystem services: a case study in Corvallis, Oregon. Presented at Ecological Society of America, Minneapolis, MN, August 04 - 09, 2013. Rogers, K., Jarratt, T. and Hansford, D. 2011. Torbay’s urban forest assessing urban forest effects and values - a report on the findings from the UK I-tree eco pilot project, Treeconomics, 46p. ISBN 978-0-9571371-0-3. Rogers, K., Sacre, K., Goodenough, J. and Doick, K. 2015. Valuing London’s urban forest results of the London I-Tree eco project, Hill & Garwood Printing Limited, 84p. ISBN 978-0-9571371-1-0. Seed Consulting Services, 2016. Tree ecosystem services assessment, Ridge Park. A report prepared for the City of Unley, South Australia, 94 p. Smith, W. H. 1990. Air pollution and forests. New York: Springer-Verlag. 618 p. Spirn, A. W. 1984. The granite garden: urban nature and human design, NY Basic Books, p. 334. Steiner, F. 2011. Landscape ecological urbanism: origins and trajectories. Landscape and Urban Planning, 100: 333–337. USDA. 2008. United States Department of Agriculture and Forest Service. I-Tree User’s Manual. www.itreetols.org/resources/ manuals/i-Tree%20Eco%20Users%Manual.pdf, Accessed May, 19 2016. Yatkın, S. ve Bayram, A. 2007. İzmir havasında partikül madde kirliliği: ölçüm ve değerlendirme, Dokuz Eylül Üniversitesi Mühendislik Fakültesi Fen ve Mühendislik Dergisi, 8 (2): 15-27. """# let stringRange = NSRange(location: 0, length: testString.utf16.count) let matches = regex.matches(in: testString, range: stringRange) var result: [[String]] = [] for match in matches { var groups: [String] = [] for rangeIndex in 1 ..< match.numberOfRanges { let nsRange = match.range(at: rangeIndex) guard !NSEqualRanges(nsRange, NSMakeRange(NSNotFound, 0)) else { continue } let string = (testString as NSString).substring(with: nsRange) groups.append(string) } if !groups.isEmpty { result.append(groups) } } print(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 Swift 5.2, please visit: https://developer.apple.com/documentation/foundation/nsregularexpression