Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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

/
/
s

Test String

Substitution

Processing...

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(ExportSTL.+?global_scale = .+?default=)(.+?),"; final String string = "# ##### BEGIN GPL LICENSE BLOCK #####\n" + "#\n" + "# This program is free software; you can redistribute it and/or\n" + "# modify it under the terms of the GNU General Public License\n" + "# as published by the Free Software Foundation; either version 2\n" + "# of the License, or (at your option) any later version.\n" + "#\n" + "# This program is distributed in the hope that it will be useful,\n" + "# but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "# GNU General Public License for more details.\n" + "#\n" + "# You should have received a copy of the GNU General Public License\n" + "# along with this program; if not, write to the Free Software Foundation,\n" + "# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" + "#\n" + "# ##### END GPL LICENSE BLOCK #####\n\n" + "# <pep8-80 compliant>\n\n" + "bl_info = {\n" + " \"name\": \"STL format\",\n" + " \"author\": \"Guillaume Bouchard (Guillaum)\",\n" + " \"version\": (1, 1, 1),\n" + " \"blender\": (2, 74, 0),\n" + " \"location\": \"File > Import-Export > Stl\",\n" + " \"description\": \"Import-Export STL files\",\n" + " \"warning\": \"\",\n" + " \"wiki_url\": \"http://wiki.blender.org/index.php/Extensions:2.6/Py/\"\n" + " \"Scripts/Import-Export/STL\",\n" + " \"support\": 'OFFICIAL',\n" + " \"category\": \"Import-Export\",\n" + "}\n\n\n" + "# @todo write the wiki page\n\n" + "\"\"\"\n" + "Import-Export STL files (binary or ascii)\n\n" + "- Import automatically remove the doubles.\n" + "- Export can export with/without modifiers applied\n\n" + "Issues:\n\n" + "Import:\n" + " - Does not handle endien\n" + "\"\"\"\n\n" + "if \"bpy\" in locals():\n" + " import importlib\n" + " if \"stl_utils\" in locals():\n" + " importlib.reload(stl_utils)\n" + " if \"blender_utils\" in locals():\n" + " importlib.reload(blender_utils)\n\n" + "import os\n\n" + "import bpy\n" + "from bpy.props import (StringProperty,\n" + " BoolProperty,\n" + " CollectionProperty,\n" + " EnumProperty,\n" + " FloatProperty,\n" + " )\n" + "from bpy_extras.io_utils import (ImportHelper,\n" + " ExportHelper,\n" + " orientation_helper_factory,\n" + " axis_conversion,\n" + " )\n" + "from bpy.types import Operator, OperatorFileListElement\n\n\n" + "IOSTLOrientationHelper = orientation_helper_factory(\"IOSTLOrientationHelper\", axis_forward='Y', axis_up='Z')\n\n\n" + "class ImportSTL(Operator, ImportHelper, IOSTLOrientationHelper):\n" + " \"\"\"Load STL triangle mesh data\"\"\"\n" + " bl_idname = \"import_mesh.stl\"\n" + " bl_label = \"Import STL\"\n" + " bl_options = {'UNDO'}\n\n" + " filename_ext = \".stl\"\n\n" + " filter_glob = StringProperty(\n" + " default=\"*.stl\",\n" + " options={'HIDDEN'},\n" + " )\n" + " files = CollectionProperty(\n" + " name=\"File Path\",\n" + " type=OperatorFileListElement,\n" + " )\n" + " directory = StringProperty(\n" + " subtype='DIR_PATH',\n" + " )\n\n" + " global_scale = FloatProperty(\n" + " name=\"Scale\",\n" + " soft_min=0.001, soft_max=1000.0,\n" + " min=1e-6, max=1e6,\n" + " default=1.0,\n" + " )\n\n" + " use_scene_unit = BoolProperty(\n" + " name=\"Scene Unit\",\n" + " description=\"Apply current scene's unit (as defined by unit scale) to imported data\",\n" + " default=False,\n" + " )\n\n" + " def execute(self, context):\n" + " from . import stl_utils\n" + " from . import blender_utils\n" + " from mathutils import Matrix\n\n" + " paths = [os.path.join(self.directory, name.name)\n" + " for name in self.files]\n\n" + " scene = context.scene\n\n" + " # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000.\n" + " global_scale = self.global_scale\n" + " if scene.unit_settings.system != 'NONE' and self.use_scene_unit:\n" + " global_scale /= scene.unit_settings.scale_length\n\n" + " global_matrix = axis_conversion(from_forward=self.axis_forward,\n" + " from_up=self.axis_up,\n" + " ).to_4x4() * Matrix.Scale(global_scale, 4)\n\n" + " if not paths:\n" + " paths.append(self.filepath)\n\n" + " if bpy.ops.object.mode_set.poll():\n" + " bpy.ops.object.mode_set(mode='OBJECT')\n\n" + " if bpy.ops.object.select_all.poll():\n" + " bpy.ops.object.select_all(action='DESELECT')\n\n" + " for path in paths:\n" + " objName = bpy.path.display_name(os.path.basename(path))\n" + " tris, pts = stl_utils.read_stl(path)\n" + " blender_utils.create_and_link_mesh(objName, tris, pts, global_matrix)\n\n" + " return {'FINISHED'}\n\n\n" + "class ExportSTL(Operator, ExportHelper, IOSTLOrientationHelper):\n" + " \"\"\"Save STL triangle mesh data from the active object\"\"\"\n" + " bl_idname = \"export_mesh.stl\"\n" + " bl_label = \"Export STL\"\n\n" + " filename_ext = \".stl\"\n" + " filter_glob = StringProperty(default=\"*.stl\", options={'HIDDEN'})\n\n" + " global_scale = FloatProperty(\n" + " name=\"Scale\",\n" + " min=0.01, max=1000.0,\n" + " default=1.0,\n" + " )\n\n" + " use_scene_unit = BoolProperty(\n" + " name=\"Scene Unit\",\n" + " description=\"Apply current scene's unit (as defined by unit scale) to exported data\",\n" + " default=False,\n" + " )\n" + " ascii = BoolProperty(\n" + " name=\"Ascii\",\n" + " description=\"Save the file in ASCII file format\",\n" + " default=False,\n" + " )\n" + " use_mesh_modifiers = BoolProperty(\n" + " name=\"Apply Modifiers\",\n" + " description=\"Apply the modifiers before saving\",\n" + " default=False,\n" + " )\n\n\n" + " def execute(self, context):\n" + " from . import stl_utils\n" + " from . import blender_utils\n" + " import itertools\n" + " from mathutils import Matrix\n" + " keywords = self.as_keywords(ignore=(\"axis_forward\",\n" + " \"axis_up\",\n" + " \"global_scale\",\n" + " \"check_existing\",\n" + " \"filter_glob\",\n" + " \"use_scene_unit\",\n" + " \"use_mesh_modifiers\",\n" + " ))\n\n" + " scene = context.scene\n\n" + " # Take into account scene's unit scale, so that 1 inch in Blender gives 1 inch elsewhere! See T42000.\n" + " global_scale = self.global_scale\n" + " if scene.unit_settings.system != 'NONE' and self.use_scene_unit:\n" + " global_scale *= scene.unit_settings.scale_length\n\n" + " global_matrix = axis_conversion(to_forward=self.axis_forward,\n" + " to_up=self.axis_up,\n" + " ).to_4x4() * Matrix.Scale(global_scale, 4)\n\n" + " faces = itertools.chain.from_iterable(\n" + " blender_utils.faces_from_mesh(ob, global_matrix, self.use_mesh_modifiers)\n" + " for ob in context.selected_objects)\n\n" + " stl_utils.write_stl(faces=faces, **keywords)\n\n" + " return {'FINISHED'}\n\n\n" + "def menu_import(self, context):\n" + " self.layout.operator(ImportSTL.bl_idname, text=\"Stl (.stl)\")\n\n\n" + "def menu_export(self, context):\n" + " default_path = os.path.splitext(bpy.data.filepath)[0] + \".stl\"\n" + " self.layout.operator(ExportSTL.bl_idname, text=\"Stl (.stl)\")\n\n\n" + "def register():\n" + " bpy.utils.register_module(__name__)\n\n" + " bpy.types.INFO_MT_file_import.append(menu_import)\n" + " bpy.types.INFO_MT_file_export.append(menu_export)\n\n\n" + "def unregister():\n" + " bpy.utils.unregister_module(__name__)\n\n" + " bpy.types.INFO_MT_file_import.remove(menu_import)\n" + " bpy.types.INFO_MT_file_export.remove(menu_export)\n\n\n" + "if __name__ == \"__main__\":\n" + " register()\n"; final String subst = "${1}10.0,"; final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceFirst(subst); System.out.println("Substitution result: " + 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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html