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

/
/
s

Test String

Code Generator

Generated Code

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

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 Rust, please visit: https://docs.rs/regex/latest/regex/