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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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"
"
gm

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"([A-Za-z-]{2,}( [a-z-]+)*[ \t\n])([|\[lLf].{1,30}[\]jJfl|])[\d\. ]*(n|(adv)|a|(v))(( [\w\s)(.,:;~‘’/\-\\'`]+)([\w()]{4,}\.))" test_str = ("- 8-\n" "Aa\n" "A, a [ei] n ingliz tili alifbosining birinchi harfi;\n" "from A to Z a) boshidan oxirigacha; b) mukammal. a [ei] (urg ‘uliyoki to ‘liq shaklif [o| (urg ‘usiz yoki reduksiyaga uchragan sluikli): 1) gram, undosh harf bilan boshlanadigan so'zlardan oldin qo'llanadigan noaniq artiklning shakli; a pencil qalam; 2) bir, bitta; this newspaper costs a dollar bu gazetaning narxi bir dollar turadi. ab- [aeb-] pref. bo'lishsiz shaklda ishlatiladigan prefiks, masalan: abnormal notabiiy, aqldan ozgan, esi past, tentak.\n" "abac ['eibaekj n mat. to‘r shaklidagi (to'rsimon) nomogramma; nomogramma (turli kattaliklar o ‘r- tasidagi o ‘zaro bog ‘lanishni ko ‘rsatadigan va ular- ni topishni osonlashtiradigan grafik chizma). abaca ['aeboko] n 1) bot. abaka daraxli yoki shu daraxtdan qilingan ip; 2) kanoptola; 3) me'mor. boshtirgak.\n" "abaci [ 'aebosi] pi abacus dan.\n" "aback [o'baek] adv I) orqaga; 2) orqasidan; 3) or-\n" "qasi bilan; to hold oneself - from......dan o‘zini\n" "uzoqda olib yurmoq; to stand ~ from dan o'zini olib qochmoq.\n" "abaction [asb'a:kjn] n yitr. katta o‘g‘irlik yoki molni o‘g‘irlash.\n" "abaculus [jaebo'kjudos] n marmar plita. abacus ['aebokos] n (pi -ci, -es [-iz]) 1) me’mor. boshtirgak; ustunning tepa qismi; 2) mat. cho't, hisobcho't; to operate, use an ~ cho'tda hisoblamoq, cho‘t qoqmoq, cho't solmoq. abaft [o 'ba;ft] 1. adv deng. qayiqning orqasidan, qayiqning izidan; 2.prep, orqasida(n), ketida(n); keyin; ~ the beam traverz orqasidan (traverz- kemaning yo'nalishiga perpendikular bo'lgan yon I onion).\n" "abandon [o'baendon] 1. v 1) bosh tortmoq; bekor qilmoq; to ~ a right huquqni bekor qilmoq; 2) tashlab ketmoq; 3) adashtirmoq; 4) qoldir- moq; 2. n odobsizlik; o'zini tuta olmaslik. abandoned [o basndond] a bosh tortgan, bahridan o'tgan, voz kechgan; tashlab ketilgan, qoldi- rilgan; tashlandiq, tashlandi; an ~ child tashlab ketilgan bola.\n" "abandonee [3,baendo'ni:] n kemani falokatdan sug'urta qilish.\n" "abandonment [a 'baendonmont] n 1) qarovsiz qoldirib ketish; 2) yur. bolasini yoki xotinini tashlab ketish.\n" "abase [o'beis] w 1) kamsitmoq; yerga (pastga) urmoq; to ~ oneself o'zini (kamsitmoq) yerga urmoq; 2) tushirmoq (mansabdan). abasement [o'betsmant] n 1) kamsitish; 2) tu- shirish (mansabdan).\n" "abash [a'baej] v uyaltirmoq, uyallirib qo'ymoq, uyatga qoldirmoq, xijolat qilmoq, xijolatga solmoq.\n" "abashed [a 'baejt] l. p.p. abash dan; 2. a uyalli- rilgan, xijolatda qolgan.\n" "abashment [a'baejmant] n uyalib qolish, xijolat bo'lish, xijolat tortish.\n" "abate [o'beit] w 1) kuchsizlantirmoq; pasaytirmoq; kamaytirmoq; to ~ the pain og'riqni pasaytirmoq; 2) o'tmas qilmoq (uclmi, tig‘ni)\\ to ~ the knife pichoqni o'tmas qilib qo'ymoq; 3) yur. bekor qilmoq.\n" "abatement [a'beitmantj n I) kuch-quvvatdan qolish, zaiflashish; ~ of noise a) shovqin bilan kurashish; b) shovqinning pasayishi; 2) tushirish (narxni, soliqni); to make - narxni tushirmoq; 3) yur. bekor qilish; - of action sud ishini to‘x- tatmoq.\n" "abatis, abbatis ['aebotisj n ag'darilgan daraxtlar- dan qilingan to'siq.\n" "abat-jour [aba'3u:r] nfr. esk. 1) lampa qalpog'i; 2) shiftdagi tuynuk; 3) shiftdagi tuynukdan tusha- digan yorug'lik.\n" "abattoir ['aebotwa;] nfr. qushxona, kushxona (chorva mollarini so'yish, go'sht, yog' tayyor- lash bilan shug'ullanuvchi korxona). abatvoix [^bcrvwa:] nfr. max. akustik ekran. abb ['acb] n to'qim. arqoq. abbacy [ 'aebosij n abbat unvoni, abbatlik. abbess ( 'aebes] n abbatisa (katolik ayollar mo- nastirining boshlig'/); rohiba. abbey ['acbi] n abbatlik (katoliklar monastiri va unga qarashli yer-mulk), monastir; the Abbey Vestminstr abbatligi.\n" "abbot [ 'asbot] n abbat (1. katolik erkaklar mo- nastirining boshlig'i; 2. Fransiyada: katoliklar ruhoniysi).\n" "abbreviate [o'bri:vieit] v qisqartirmoq; ~d qisqartirilgan.\n" "abbreviation [3,bri:vi 'eijn] n qisqartirish; qis- qartma.\n" "ABC [,eibi:'si:J n 1) alifbo; ~ book alifbo kitobi; 2) asos, negiz.\n" "abdicate ['aebdikeit] v kechmoq, voz kechmoq, yuz o'girmoq, bahridan o'tmoq, o'zini mahrum qilmoq (taxtdan, hokimiyatdan, o'zhuquqidan). abdication Laebdi'keijon] n kechish, voz kechish, yuz o'girish, bahridan o'tish, o'zini mahrum qilish (nimadandir).\n" "abdomen ['aebdomen] n 1) anat. qorin, qorin bo'shlig'i; retracted - ichiga kirgan qorin; 2) zool. qorin (qushlarda). abdominal [aeb'daminl] a anat. qoringa oid, qorin...; - pain qorin og'rig'i; ~ cavity qorin bo'shlig'i.\n" "abdominous [asb'dominos] a semiz, yo'g'on, qor- ni katta.\n" "abducent [ocb'dju:sont] a anat. ajratadigan (mus- kullar to'g'risida), mushaklarning tortilishi. abduct [ob'dxkt] v (zo'rlab, majburan) o'g'irla- moq, o'g'irlab ketmoq, olib qochmoq (from)-.abdonate\n" "to - a child from its home bolani uyidan olib qochmoq,\n" "abduction [reb'dAkJn] n (zo'rlab, majburan) o‘g‘ir]ash, o'g'irlab ketish; olib qochish (asosan, bolalar va ayolhirni).\n" "abductor [aeb'dAkta] n o‘g‘ri, o‘g‘irlovchi; olib- qochar (asosan, bolalar va ayollami). abeam [a bi:m] adv deng. kemaning izidan, orqa- sidan.\n" "abear [a 'beaj v toqat qilmoq, chidamoq. abecedarian [,etbi:si:'deanan] 1. a 1) alifbo tartibida joylashtirilgan; 2) oddiy, sodda; 2. n savod o'rgatadigan, o'qituvchi. abed [a'bed] adv 1) ko'rpa-to'shakda; karavotda;\n" "2) ko'rpa-to'shakka, karavotga. abele [a'bi:l, eibl] n bat. oq terak. aberdevine [,aebada'vainj n log'chumchuq (modasi).\n" "aberrance, -cy [as'berans, -sij n 1) to'g'ri yo'ldan chiqish; 2) biol. normal turdan chetga chiqish. aberrant [ae'berant] a 1) adashgan, adashib qolgan, yo'lini yo'qotib qo'ygan; 2) og‘gan, chetga chiqqan, burilib ketgan; a plane on an - course belgilangan yo'ldan chetga chiqib ketgan samolyot.\n" "aberration [,aeba'reijn] n adashish, adashib qolish, yoMini yo'qotish. abet [o'bet] v yomon ishga undamoq (in): to - smb. in a crime yur. kimnidir jinoyat sodir etish- ga undamoq.\n" "abetment [a'betmant ] n ig‘vo, fitna. abetter [a'beta] n 1) sherik; 2) g'iybatchi, g'ala- mis, fitnachi.\n" "abettor [a 'beta] = abetter, abeyance [a'beians] n 1) noma’lum, mavhum holat; 2) yur. vaqtincha amalda bo'lmaslik, vaqtincha bekor qilinish (qonun, huquq): the question is in- bu masalani ko'rib chiqish to'xtatildi; this rule has fallen into - bu qonun eskirgan (boshqa amal qilmaydi); in - a) mavhum, kutish holatida: b) egasiz (meros to'g'- risida); d) vaqtincha bekor qilingan (qonun to ‘g 'risida).\n" "abhor [ab'ha:] v 1) juda yomon ko'rmoq; nafrat bilan qaramoq; 2) so'zl. toqat qila olmaslik; yoqtirmaslik; my son ~s being idle o'g'lim bekor yurishni yoqlirmaydi. abhorrence [ab'harans] n jirkanish, nafratlanish, yomon ko'rish: to hold in - nafratlanmoq, jir- kanmoq.\n" "abhorrent [ab'harant] a 1) nafrat uyg'otadigan:\n" "2) birga yashay olmaydigan, birga bo'lolmay- digan (to - bilan).\n" "abidance [a'bajdans] n rioya qilish ( nimagadir)-,\n" "~ by rules qoidaga rioya qilmoq.\n" "abide [o'baid] v (abode, abided, abidden)\n" "1) chidamli (pishiq) bo'lmoq; buzilmas bo'lib qolmoq: 2) ya.shamoq: umr ko'rmoq, istiqomat\n" "qilmoq; ~ at biror joyda (istiqomat qilmoq) yashamoq; - by sodiq bo'lib qolmoq: rioya qilmoq: amal qilmoq; to - by one’s promises so'zining (va’dasining) ustidan chiqmoq: my father ~s by what he said mening otam doimo aytganini qiladi; - in biror joyda (istiqomat qilmoq) yashamoq; - with kirn bilandirqolmoq. abiding [o'baidiq] 1. pres. p. abide dan; 2. a doi- miy, o'zgarmas, abadiy, mustahkain; - friendship mustahkam do'stlik. ability [a'biltti] n qobiliyat, iste’dod, mahorat; (at, in; to + inf.); - to hear eshitish qobiliyali; negotiation - to'siqlarni yengish qobiliyati; he is a master of - u mohir usta; the - to read o'qish qobiliyati.\n" "abirritate [as'biriteitj v rib. asabiylashni pasay- tirmoq.\n" "abject ['rebdjekt) a 1) ayanchli, qabih, yaramas, pastkash, razil: past; in - poverty juda nochor ahvolda; 2) xo'rlangan, haqoratlangan, kamsitil- gan.\n" "ensoul [in'saul] v ruhlanlirmoq; ilhomlanlirmoq, ruhini ko'tarmoq, g'ayratini oshirmoq. ensue [in'sju:] v 1) kimsa yoki narsaning izidan (kelidan, orqasidan) bormoq; 2) oqib lamom bo'lmoq, batamom oqib ketmoq. en suite [,on'swi:l] a qo‘shma, yonma-yon. ensure [in'Jo:] 1. v 1) saqlamoq; 2) sug'urla qil- moq; himoya qilmoq; 2. n ta’minlamoq, kafolal berish, himoya qilish. entablature [en'taeblatja] = entablement, entablement [m'teibltnant| n me’mor. antable- ment (shiflning bevosita ustunlarga layangan bezakli qismlari).\n" "entail [in'teil] 1. v sabab bo'lmoq, ...ga olib bormoq; 2. n mayoral (feodalizmdan qolgan vorislik larlibi).\n" "entangle [in'tasqgl] v chalkashtirmoq, chalkash- chulkash qilib yubormoq. entangled [in'laeqgld] a ushlangan, tutilgan, ilin- gan.\n" "entanglement [in'taeqglmantj n 1) chalkashlik, chigallik; 2) qiyin (tang) ahvol; 3) harb. (tikanli) sim to‘siq.\n" "enter [enta] v 1) kirmoq (ichkariga); to ~a room xonaga kirmoq; 2) to - the army armiya safiga kirmoq: 3) ro'yxatga kirmoq; 4) qatnashmoq; to - a race poygada qatnashmoq; - into kirmoq; ~ on kirishmoq.\n" "enteric [en 'terik] 1. anal, a qoringa oid, qorin; 2. n lib. ich terlama.\n" "enterprise ['entapraiz] n 1) muassasa, korxona; private - xususiy korxona; 2) uddaburonlik, epchillik, tashabbuskorlik. enterprising ['entopratziq] a uddaburon, epchil; tashabbuskor.\n" "entertain [,enta'tern] v 1) mehmonlami qabul qilmoq, mehrnon qilmoq; 2) ko‘ngil ochmoq. entertaining [,ents'leiniq] 1. pres. p. entertain dan; 2. a 1) qiziq, ajib, g'alati; 2) ko'ngil ochadi- gan, vaqtni chog1 qiladigan. entertainment [,ento leinmantj n 1) mehmonlarni qabul qilish; 2) o'yin-kulgi; sayr-tomosha. enthral(l) [in'0ro:I] v o‘ziga tortmoq, jalb qilmoq.\n" "enthralling [in'0ro:lii]J 1 .pres. p. enthral(l)dan: 2. a qiziq, qiziqtiradigan, zavqli, maroqli, jozi- bador, zavq (havas) keltiradigan. enthrone [m'Orounl v taxtga o’tqazmoq, podsho qilib ko'tarmoq.\n" "enthusiasm |in'0ju:zi,a;zm| n shavq-zavq, g‘ay- rat, ishtiyoq, tashabbus.\n" "enthusiast |in'0ju:ziaestj n g'ayral (shavq-zavq) biIan ishlaydigan odam, tashabbuskor. enthusiastic | in/0ju:>a'aestikj a zavqli, quvonchli, zavqqa to‘lgan, o'zida yo‘q xursand. enthusiastically [in,8ju:zi'aeslkli] adv g‘ayrat bilan, ishtiyoq bilan.\n" "entice |in'lais| v qiziqtirmoq, havasini keltir- moq.\n" "enticement [in'taismont] n qiziqtiradigan narsa. enticing [in'laisiq] 1. pres. p. entice dan\\ 2. a yo'ldan ozdiruvchi, vasvasa qiluvchi. entire [in'tara] a to'la, butun, tugallangan, to'liq, to‘la-lo‘kis, mukammal.\n" "entirely [in'laioll] adv to'la, to'liq, batamom, to'la-lo'kis, lamomila.\n" "entirety [in'iaiati] n to'lalik, lo'liqlik; 2) butunlik, yaxlitlik.\n" "entitle [inlaid] v 1) sarlavha qo'ymoq; 2) vakolat bermoq.\n" "entity ['entoti] n I) lurmush, borliq; 2) mohiyat, tub (asosiy) mazmun.") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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