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

/
/
g

Test String

Code Generator

Generated Code

const regex = /^---([\s\S]*?)---[\n\s\S]\n/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('^---([\\s\\S]*?)---[\\n\\s\\S]\\n', 'g') const str = `--- author: nick: Unknown link: https://www.blogger.com/profile/00073980860956332189 email: noreply@blogger.com category: [] comments: true cover: https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/12.png date: 2017-08-29T20:38:00.000+07:00 lang: en location: "" modified: 2017-08-29T20:38:03.355+07:00 subtitle: "- -- Database: \`codeigniter_crud\` -- -- -------------------------------------------------------- -- -- Table structure for table \`siswa\`" tags: - Wordpress - CodeIgniter title: How to Multiple Delete With CodeIgniter type: post uuid: 47c30314-bfb9-4888-8c55-7c27fc5c6d79 webtitle: WMI Gitlab updated: 2017-08-29T20:38:03+07:00 thumbnail: https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/12.png photos: - https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/12.png description: "- -- Database: \`codeigniter_crud\` -- -- -------------------------------------------------------- -- -- Table structure for table \`siswa\`" --- In this tutorial I will discuss about how to create <strong>Multiple Delete With CodeIgniter</strong> , If you guys often use wordpress definitely friends will know, because wordpress apply this in their system. <br>First prepare your codeigniter folder named <strong>delete_multiple,</strong> Here I assume friends already know how to setup <a href="http://translate.googleusercontent.com/translate_c?depth=1&amp;nv=1&amp;rurl=translate.google.com&amp;sl=id&amp;sp=nmt4&amp;tl=en&amp;u=http://www.tutorial-webdesign.com/menghilangkan-index-php-di-codeigniter/&amp;usg=ALkJrhip-cCW96nqXDsM897bt2TR85zOLw" title="Initial Setting of Codeigniter" rel="noopener noreferer nofollow"> initial CodeIgniter </a> like config.php, autoload.php dll, database.php. We will use the Controller welcome.php default is Codeigniter or at least have followed <a href="http://translate.googleusercontent.com/translate_c?depth=1&amp;nv=1&amp;rurl=translate.google.com&amp;sl=id&amp;sp=nmt4&amp;tl=en&amp;u=http://www.tutorial-webdesign.com/tutorial-dasar-penggunaan-codeigniter/&amp;usg=ALkJrhikrwwVzw88VfaG_e_MzeLpO6V09Q" title="Basic Code Usage Tutorial" rel="noopener noreferer nofollow"> the basic tutorial of the use of Codeigniter </a> . <br><em><strong>Read Also:</strong></em> <a href="http://translate.googleusercontent.com/translate_c?depth=1&amp;nv=1&amp;rurl=translate.google.com&amp;sl=id&amp;sp=nmt4&amp;tl=en&amp;u=http://www.tutorial-webdesign.com/tutorial-crud-create-read-update-dan-delete-menggunakan-codeigniter-1/&amp;usg=ALkJrhiZVe1_zRpzNzvhPw2Uk_O6iWlpDw" title="Crud Part 1" rel="noopener noreferer nofollow"> CRUD Tutorial (Create, Read, Update and Delete) With CodeIgniter - Part 1 </a> &amp; <a href="http://translate.googleusercontent.com/translate_c?depth=1&amp;nv=1&amp;rurl=translate.google.com&amp;sl=id&amp;sp=nmt4&amp;tl=en&amp;u=http://www.tutorial-webdesign.com/tutorial-crud-create-read-update-dan-delete-dengan-codeigniter-part-2/&amp;usg=ALkJrhjFwUin_JBxbalzEhx_AuTUIQ-41A" title="CRUD Part 2" rel="noopener noreferer nofollow"> Part 2 </a><br>Next create a database <strong>codeigniter_crud</strong> , create a <strong>student</strong> table like the following conditions below sqlnya: <br><div><pre><code>-- -- Database: \`codeigniter_crud\` -- -- -------------------------------------------------------- -- -- Table structure for table \`siswa\` -- CREATE TABLE IF NOT EXISTS \`siswa\` ( \`nis\` bigint(11) NOT NULL, \`nama\` varchar(30) NOT NULL, \`jurusan\` varchar(10) NOT NULL, \`alamat\` text NOT NULL ) ENGINE=InnoDB AUTO_INCREMENT=998765336 DEFAULT CHARSET=latin1; -- -- Dumping data for table \`siswa\` -- INSERT INTO \`siswa\` (\`nis\`, \`nama\`, \`jurusan\`, \`alamat\`) VALUES (998765122, 'Yusuf Hamdani', 'RPL', 'Jln. Cipaku Haji Rt.02/07 No.15 Kel.Cipaku Kec.Bogor Selatan'), (998765335, 'Rahmayanti', 'Multimedia', 'Jln. Muarasari, Kel.Gunung Batu Kec.Bogor Barat'); -- -- Indexes for dumped tables -- </code></pre><div>Codeigniter_crud.sql </div></div>Open <strong>Controller welcome.php</strong> then edit as below: <br><div><pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Welcome extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/&lt;method_name&gt; * @see http://codeigniter.com/user_guide/general/urls.html */ public function index() { \$this-&gt;load-&gt;model('msiswa'); \$data['hasilsiswa'] = \$this-&gt;msiswa-&gt;ambildata(); \$this-&gt;load-&gt;view('index', \$data); } function delete_multiple() { \$this-&gt;load-&gt;model('msiswa'); \$this-&gt;msiswa-&gt;remove_checked_siswa(); redirect('welcome/index'); } } /* End of file welcome.php */ /* Location: ./application/controllers/welcome.php */ </code></pre><div>Welcome.php </div></div>Create a new file in the <strong>Models</strong> folder where <strong>msiswa.php</strong> : <br><div><pre><code>&lt;?php class Msiswa extends CI_Model { function ambildata() { \$ambildata = \$this-&gt;db-&gt;get('siswa'); if (\$ambildata-&gt;num_rows() &gt; 0) { foreach (\$ambildata-&gt;result() as \$data) { \$hasilsiswa[] = \$data; } return \$hasilsiswa; } } function remove_checked_siswa() { \$action = \$this-&gt;input-&gt;post('action'); if (\$action == "delete") { \$delete = \$this-&gt;input-&gt;post('msg'); for (\$i=0; \$i &lt; count(\$delete) ; \$i++) { \$this-&gt;db-&gt;where('nis', \$delete[\$i]); \$this-&gt;db-&gt;delete('siswa'); } } } } ?&gt; </code></pre><div>Msiswa.php </div></div>The snippet of this image describes the coding to display the existing data in the database<strong>codeigniter_crud</strong> <strong>student</strong> table <strong>:</strong><br><div><div><ins id="aswift_0_expand"><ins id="aswift_0_anchor"></ins></ins></div></div><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/12.png" rel="noopener noreferer nofollow"> <img alt="1" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/12.png" height="153" width="444"> </a><br>This is for the process when the data will be deleted: <br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/21.png" rel="noopener noreferer nofollow"> <img alt="2" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/21.png" height="161" width="430"> </a><br>Then create a new file in the <strong>Views</strong> folder named <strong>index.php</strong> : <br><div><pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;AZZURA Media | Membuat Multiple Delete Dengan CodeIgniter&lt;/title&gt; &lt;script type="text/javascript" src="&lt;?php echo base_url(''); ?&gt;assets/js/jquery-1.5.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; \$(document).ready(function() { \$("input[name='checkAll']").click(function() { var checked = \$(this).attr("checked"); \$("#myTable tr td input:checkbox").attr("checked", checked); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Multiple Delete Dengan CodeIgniter&lt;/h1&gt; &lt;form action="&lt;?php echo site_url('welcome/delete_multiple'); ?&gt;" method="post"&gt; &lt;select name="action"&gt; &lt;option value="null"&gt;Bulk Action&lt;/option&gt; &lt;option value="delete"&gt;Delete&lt;/option&gt; &lt;/select&gt; &lt;input type="submit" name="submit" value="Action"&gt; &lt;p&gt;&lt;/p&gt; &lt;table border="1" id="myTable"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;input type="checkbox" id="checkAll" name="checkAll"&gt;&lt;/th&gt; &lt;th&gt;NIS&lt;/th&gt; &lt;th&gt;Nama&lt;/th&gt; &lt;th&gt;Jurusan&lt;/th&gt; &lt;th&gt;Alamat&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;?php if (count(\$hasilsiswa)&gt;0) { foreach (\$hasilsiswa as \$data): ?&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="checkbox" name="msg[]" value="&lt;?php echo \$data-&gt;nis; ?&gt;"&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo \$data-&gt;nis; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo \$data-&gt;nama; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo \$data-&gt;jurusan; ?&gt;&lt;/td&gt; &lt;td&gt;&lt;?php echo \$data-&gt;alamat; ?&gt;&lt;/td&gt; &lt;/tr&gt; &lt;?php endforeach; } else { echo "&lt;tr&gt;&lt;td colspan=5&gt;DATA KOSONG!!&lt;/td&gt;&lt;/tr&gt;"; } ?&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre><div>Index.php </div></div>Description in the <strong>index.php</strong> file <strong>, you</strong> must first download <a href="http://translate.googleusercontent.com/translate_c?depth=1&amp;nv=1&amp;rurl=translate.google.com&amp;sl=id&amp;sp=nmt4&amp;tl=en&amp;u=http://docs.jquery.com/Selectors/checked&amp;usg=ALkJrhj8cVA4M28DQA2-1ei1ppSFutWFfw" target="_blank" rel="noopener noreferer nofollow"> JQuery Docs: Selectors / checked </a> then input jquery script to checkAll below: <br><div><pre><code>&lt;script type="text/javascript"&gt; \$(document).ready(function() { \$("input[name='checkAll']").click(function() { var checked = \$(this).attr("checked"); \$("#myTable tr td input:checkbox").attr("checked", checked); }); }); &lt;/script&gt; </code></pre><div></div></div><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/33.png" rel="noopener noreferer nofollow"> <img alt="3" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/33-450x132.png" height="132" width="450"> </a><br><em><strong>Read Also:</strong></em> <a href="http://translate.googleusercontent.com/translate_c?depth=1&amp;nv=1&amp;rurl=translate.google.com&amp;sl=id&amp;sp=nmt4&amp;tl=en&amp;u=http://www.tutorial-webdesign.com/check-uncheck-all-jquery/&amp;usg=ALkJrhja2BuoFYDym4uQpvAU2M5RnnP1ZA" title="Tutorial Check &amp; Uncheck all checkbox" rel="noopener noreferer nofollow"> Tutorial Making Check &amp; Uncheck All Checkboxs with Jquery </a><br>In the table script snippet you enter the id to call the javascript function that we apply: <br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/4.png" rel="noopener noreferer nofollow"> <img alt="4" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/4-450x40.png" height="40" width="450"> </a><br>Named the checkbox id like this, intended to call the javascript function we created, when the checkbox is clicked fed automate all checkAll: <br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/51.png" rel="noopener noreferer nofollow"> <img alt="5" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/51-450x60.png" height="60" width="450"> </a><br>For the post method submitted by the input checkbox we created, we named the checkbox mgs [], to create the array when the data is deleted, following the script snippet: <br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/61.png" rel="noopener noreferer nofollow"> <img alt="6" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/61-450x76.png" height="76" width="450"> </a><br>After completing all the above discussion, you can directly try the program that friend made earlier, if it is correct it will appear as below, so when checkbox next door clicked to eat data will check all, and to delete data Sahabat must choose Select Bulk Action Changed to Delete option then press Action button: <br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/8.png" rel="noopener noreferer nofollow"> <img alt="8" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/8-450x281.png" height="281" width="450"> </a><br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/9.png" rel="noopener noreferer nofollow"> <img alt="9" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/9-450x281.png" height="281" width="450"> </a><br><a href="http://www.tutorial-webdesign.com/wp-content/uploads/2015/01/10.png" rel="noopener noreferer nofollow"> <img alt="10" src="https://www.tutorial-webdesign.com/wp-content/uploads/2015/01/10-450x281.png" height="281" width="450"> </a><br>Okay, so my tutorial this time about Multiple Delete With Codeigniter. <br>Hope can increase knowledge of Friends: D: D <br><a href="https://www.dropbox.com/s/oxlegea0shsoqnb/delete_multiple.zip?dl=0" target="_blank" rel="noopener noreferer nofollow">Download Tutorial </a>`; // 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