Save & Share

  • Current Version: 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

$re = '~(?:\$|jQuery)\.mage\.__\((?s)[^\'"]*?([\'"])(.+?)(?<!\\\\)\1(?s).*?\)~'; $str = '/** * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ define([ \'jquery\', \'ko\', \'module\', \'../template/renderer\', \'mage/translate\' ], function ($, ko, module, renderer) { \'use strict\'; var locations = { \'legend\': \'Caption for the fieldset element\', \'label\': \'Label for an input element.\', \'button\': \'Push button\', \'a\': \'Link label\', \'b\': \'Bold text\', \'strong\': \'Strong emphasized text\', \'i\': \'Italic text\', \'em\': \'Emphasized text\', \'u\': \'Underlined text\', \'sup\': \'Superscript text\', \'sub\': \'Subscript text\', \'span\': \'Span element\', \'small\': \'Smaller text\', \'big\': \'Bigger text\', \'address\': \'Contact information\', \'blockquote\': \'Long quotation\', \'q\': \'Short quotation\', \'cite\': \'Citation\', \'caption\': \'Table caption\', \'abbr\': \'Abbreviated phrase\', \'acronym\': \'An acronym\', \'var\': \'Variable part of a text\', \'dfn\': \'Term\', \'strike\': \'Strikethrough text\', \'del\': \'Deleted text\', \'ins\': \'Inserted text\', \'h1\': \'Heading level 1\', \'h2\': \'Heading level 2\', \'h3\': \'Heading level 3\', \'h4\': \'Heading level 4\', \'h5\': \'Heading level 5\', \'h6\': \'Heading level 6\', \'center\': \'Centered text\', \'select\': \'List options\', \'img\': \'Image\', \'input\': \'Form element\' }, /** * Generates [data-translate] attribute\'s value * @param {Object} translationData * @param {String} location */ composeTranslateAttr = function (translationData, location) { var obj = [{ \'shown\': translationData.shown, \'translated\': translationData.translated, \'original\': translationData.original, \'location\': locations[location] || \'Text\' }]; return JSON.stringify(obj); }, /** * Sets text for the element * @param {Object} el * @param {String} text */ setText = function (el, text) { $(el).text(text); }, /** * Sets [data-translate] attribute for the element * @param {Object} el - The element which is binded * @param {String} original - The original value of the element */ setTranslateProp = function (el, original) { var location = $(el).prop(\'tagName\').toLowerCase(), translated = $.mage.__(original), translationData = { shown: translated, translated: translated, original: original }, translateAttr = composeTranslateAttr(translationData, location); $(el).attr(\'data-translate\', translateAttr); setText(el, translationData.shown); }, /** * Checks if node represents ko virtual node (nodeType === 8, nodeName === \'#comment\'). * * @param {HTMLElement} node * @returns {Boolean} */ isVirtualElement = function (node) { return node.nodeType === 8; }, /** * Checks if it\'s real DOM element * in case of virtual element, returns span wrapper * @param {Object} el * @param {bool} isUpdate * @return {Object} el */ getRealElement = function (el, isUpdate) { if (isVirtualElement(el)) { if (isUpdate) { return $(el).next(\'span\'); } return $(\'<span/>\').insertAfter(el); } return el; }, /** * execute i18n binding * @param {Object} element * @param {Function} valueAccessor * @param {bool} isUpdate */ execute = function (element, valueAccessor, isUpdate) { var original = ko.unwrap(valueAccessor() || \'\'), el = getRealElement(element, isUpdate), inlineTranslation = (module.config() || {}).inlineTranslation; if (inlineTranslation) { setTranslateProp(el, original); } else { setText(el, $.mage.__(original)); } }; /** * i18n binding * @property {Function} init * @property {Function} update */ ko.bindingHandlers.i18n = { /** * init i18n binding * @param {Object} element * @param {Function} valueAccessor */ init: function (element, valueAccessor) { execute(element, valueAccessor); }, /** * update i18n binding * @param {Object} element * @param {Function} valueAccessor */ update: function (element, valueAccessor) { execute(element, valueAccessor, true); } }; ko.virtualElements.allowedBindings.i18n = true; renderer .addNode(\'translate\', { binding: \'i18n\' }) .addAttribute(\'translate\', { binding: \'i18n\' }); }); '; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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