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
No Match

r"
"
ms

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?ms)<td width=\"70%\" class=\"tdbold\">\s+<div >\s*([^<&]+).*ที่อยู่\s+([^<&]+).*โทร.\s*([0-9๐-๙- ,]+)`) var str = ` <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-18733385-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <title>ระบบสารสนเทศภฺมิศาสตร์ทรัพยากรสุขภาพ สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</title> <script type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="jquery/jquery.easing.1.3.js"></script> <script type="text/javascript" src="jquery/jquery.galleryview-1.1.js"></script> <script type="text/javascript" src="jquery/jquery.timers-1.1.2.js"></script> <script type="text/javascript" src="js/jquery_slide.js"></script> <link href="css/stylemap.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="../ckeditor/ckeditor.js"></script> <script type="text/javascript"> //<![CDATA[ CKEDITOR.replace( 'message',{ height : 400, width : 400, } ); //]]> </script> <script type="text/javascript" src="highslide/highslide-with-gallery.js"></script> <link rel="stylesheet" type="text/css" href="highslide/highslide.css" /> <script type="text/javascript"> hs.graphicsDir = 'highslide/graphics/'; hs.align = 'center'; hs.transitions = ['expand', 'crossfade']; hs.outlineType = 'glossy-dark'; hs.wrapperClassName = 'dark'; hs.fadeInOut = true; if (hs.addSlideshow) hs.addSlideshow({ interval: 4000, repeat: false, useControls: true, fixedControls: 'fit', overlayOptions: { opacity: .6, position: 'bottom center', hideOnMouseOut: true} }); </script> </head> <body> <table align ="center" width="760" cellpadding="0" cellspacing="0"><tr><td> <div id="navcontainer"> <ul id="navlist"> <!-- CSS Tabs --> <li><a href="info.php?maincode=00001" id="current">ข้อมูลทั่วไป</a></li> <li><a href="infopersonal.php?maincode=00001">ข้อมูลบุคลากร</a></li> <li><a href="infospecialty.php?maincode=00001">แพทย์เฉพาะทาง</a></li> <li><a href="infoequip.php?maincode=00001">สถานที่และเครื่องมือแพทย์</a></li> <li><a href="work.php?maincode=00001">ผลงานเด่น</a></li> <li><a href="login.php?maincode=00001">เข้าสู่ระบบ</a></li> </ul> </div> </td></tr></table> <!--table width="761" align="center" class="tableBorder"> <tr> <td width="753"--> <table width="650" align="center" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" class="tdhead650" valign="middle">ข้อมูลทั่วไป สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</td> </tr> <tr> <td width="30%">&nbsp;</td> <td width="70%">&nbsp;</td> </tr> <tr> <td align="center" valign="top"> <div class="highslide-gallery"> <a href="upload/logo/p_00001_190418_031102.png" class="highslide" onclick="return hs.expand(this)"> <img src="upload/logo/p_00001_190418_031102.png" alt="Highslide JS"title="Click to enlarge" width="100" height="100"/></a> <div class="highslide-caption"><center> สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</center></div></td> <td width="70%" class="tdbold"> <div > สำนักงานสาธารณสุขจังหวัดสมุทรปราการ&nbsp;&nbsp;<a href="gmap.php?code=00001" target="_blank"><img src="image_res/2green.png" title="แสดงในแผนที่" border="0"/></a></div><br /> <div> รหัส 00001</div><br /> <div>ที่อยู่ 19 ซอย 35 อัศวนนท์ 2 ถ.สุขุมวิท ต.ปากน้ำ อ.เมือง จ.สมุทรปราการ 10270 </div><br /> <div>ที่ตั้ง จ.สมุทรปราการ อ.เมืองสมุทรปราการ ต.ปากน้ำ หมู่ 0 </div> <br> <div>โทร. 02-3895980&nbsp;&nbsp; แฟกซ์ 02-3951034 </div> <br> <div>อีเมล์ -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; เว็บไซต์ <a href="http://www.spko.moph.go.th/" target="_new" >www.spko.moph.go.th/</a></div></td> </tr> <tr> <td>&nbsp;</td> <td></td> </tr> <tr> <td>&nbsp;</td> <td class="trBottom">ผู้บริหารและประวัติสถานพยาบาล</td> </tr> <tr> <td align="center"> <div class="highslide-gallery"> <a href="upload/ceo/p_00001_140218_134154.jpg" class="highslide" onclick="return hs.expand(this)"> <img src="upload/ceo/p_00001_140218_134154.jpg" alt="Highslide JS"title="Click to enlarge" width="100" height="100"/></a> <div class="highslide-caption"><center> สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</center></div></td> <td><br ><br /> <div >ชื่อผู้บริหาร <b>&nbsp;นพ.สวัสดิ์ อภิวัจนีวงศ์</b></div> <br /> <div > ประวัติสถานพยาบาล <a href="info_history.php?maincode=00001" title="อ่านประวัติสถานพยาบาล"><b>เพิ่มเติม</b></a> <p>&nbsp;</p> </div> </td> </tr> <tr> <td>&nbsp;</td> <td></td> </tr> </table> <table align="center"> <tr> <td> <body><div class="highslide-gallery"> <a href="upload/hospital/p_00001_190418_024043.jpg" class="highslide" onClick="return hs.expand(this)"> <img src="upload/hospital/p_00001_190418_024043.jpg" alt="Highslide JS"title="Click to enlarge" width="133" height="100"/></a> <div class="highslide-caption"><center> สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</center></div> <a href="upload/hospital/p_00001_190418_024156.jpg" class="highslide" onClick="return hs.expand(this)"> <img src="upload/hospital/p_00001_190418_024156.jpg" alt="Highslide JS"title="Click to enlarge" width="133" height="100"/></a> <div class="highslide-caption"><center> สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</center></div> <a href="upload/hospital/p_00001_190418_024306.jpg" class="highslide" onClick="return hs.expand(this)"> <img src="upload/hospital/p_00001_190418_024306.jpg" alt="Highslide JS"title="Click to enlarge" width="133" height="100"/></a> <div class="highslide-caption"><center> สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</center></div> <a href="upload/hospital/p_00001_190418_025428.jpg" class="highslide" onClick="return hs.expand(this)"> <img src="upload/hospital/p_00001_190418_025428.jpg" alt="Highslide JS"title="Click to enlarge" width="133" height="100"/></a> <div class="highslide-caption"><center> สำนักงานสาธารณสุขจังหวัดสมุทรปราการ</center></div> <br> </div> </div> </body> </td> </tr> </table> <table width="650" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="right" class="trBottom">&nbsp;</td> </tr> <tr> <td align="right" >ข้อมูลวันที่ 6 ธ.ค. 2562 15:51</td> </tr> </table> <!--/td></tr></table--> <TABLE border ='0' width ="650" align="center"> <tr><td>&nbsp;</td></tr> <TR><TD width =100% align= "center"><a href="https://play.google.com/store/apps/details?id=com.hiso.hisomap4" target="_blank"><img src="app_android.png" alt="ดาวน์โหลดได้ที่ Google Play"/></a><!-- Begin ShinyStat Free code --> <script type="text/javascript" language="JavaScript" src="http://codice.shinystat.com/cgi-bin/getcod.cgi?USER=healthHiso"></script> <noscript> <a href="http://www.shinystat.com" target="_top"> <img src="http://www.shinystat.com/cgi-bin/shinystat.cgi?USER=healthHiso" alt="Free hit counter" border="0" /></a> </noscript><a href="https://itunes.apple.com/th/app/gis-health/id859027531?mt=8" target="_blank"><img src="app_ios.png" alt="ดาวน์โหลดได้ที่ App Store"/></a> </TD><TD></TD></TR> </TABLE> </body> </html>` if len(re.FindStringIndex(str)) > 0 { fmt.Println(re.FindString(str),"found at index",re.FindStringIndex(str)[0]) } }

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 Golang, please visit: https://golang.org/pkg/regexp/