Regular Expressions 101

Save & Share

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

/
/
gm

Test String

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 = "^\\s\\S{6}\\s(?<codec>[\\w|-]+)\\s+.+$"; final String string = "Encoders:\n" + " V..... = Video\n" + " A..... = Audio\n" + " S..... = Subtitle\n" + " .F.... = Frame-level multithreading\n" + " ..S... = Slice-level multithreading\n" + " ...X.. = Codec is experimental\n" + " ....B. = Supports draw_horiz_band\n" + " .....D = Supports direct rendering method 1\n" + " ------\n" + " V..... a64multi Multicolor charset for Commodore 64 (codec a64_multi)\n" + " V..... a64multi5 Multicolor charset for Commodore 64, extended with 5th color (colram) (codec a64_multi5)\n" + " V..... alias_pix Alias/Wavefront PIX image\n" + " V..... amv AMV Video\n" + " V..... apng APNG (Animated Portable Network Graphics) image\n" + " V..... asv1 ASUS V1\n" + " V..... asv2 ASUS V2\n" + " V..X.. libaom-av1 libaom AV1 (codec av1)\n" + " V..... avrp Avid 1:1 10-bit RGB Packer\n" + " V..X.. avui Avid Meridien Uncompressed\n" + " V..... ayuv Uncompressed packed MS 4:4:4:4\n" + " V..... bmp BMP (Windows and OS/2 bitmap)\n" + " V..... cinepak Cinepak\n" + " V..... cljr Cirrus Logic AccuPak\n" + " V.S... vc2 SMPTE VC-2 (codec dirac)\n" + " VFS... dnxhd VC3/DNxHD\n" + " V..... dpx DPX (Digital Picture Exchange) image\n" + " VFS... dvvideo DV (Digital Video)\n" + " V.S... ffv1 FFmpeg video codec #1\n" + " VF.... ffvhuff Huffyuv FFmpeg variant\n" + " V..... fits Flexible Image Transport System\n" + " V..... flashsv Flash Screen Video\n" + " V..... flashsv2 Flash Screen Video Version 2\n" + " V..... flv FLV / Sorenson Spark / Sorenson H.263 (Flash Video) (codec flv1)\n" + " V..... gif GIF (Graphics Interchange Format)\n" + " V..... h261 H.261\n" + " V..... h263 H.263 / H.263-1996\n" + " V..... h263_v4l2m2m V4L2 mem2mem H.263 encoder wrapper (codec h263)\n" + " V.S... h263p H.263+ / H.263-1998 / H.263 version 2\n" + " V..... libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)\n" + " V..... libx264rgb libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)\n" + " V..... h264_nvenc NVIDIA NVENC H.264 encoder (codec h264)\n" + " V..... h264_omx OpenMAX IL H.264 video encoder (codec h264)\n" + " V..... h264_v4l2m2m V4L2 mem2mem H.264 encoder wrapper (codec h264)\n" + " V..... h264_vaapi H.264/AVC (VAAPI) (codec h264)\n" + " V..... nvenc NVIDIA NVENC H.264 encoder (codec h264)\n" + " V..... nvenc_h264 NVIDIA NVENC H.264 encoder (codec h264)\n" + " V..... libx265 libx265 H.265 / HEVC (codec hevc)\n" + " V..... nvenc_hevc NVIDIA NVENC hevc encoder (codec hevc)\n" + " V..... hevc_nvenc NVIDIA NVENC hevc encoder (codec hevc)\n" + " V..... hevc_v4l2m2m V4L2 mem2mem HEVC encoder wrapper (codec hevc)\n" + " V..... hevc_vaapi H.265/HEVC (VAAPI) (codec hevc)\n" + " VF.... huffyuv Huffyuv / HuffYUV\n" + " V..... jpeg2000 JPEG 2000\n" + " VF.... libopenjpeg OpenJPEG JPEG 2000 (codec jpeg2000)\n" + " VF.... jpegls JPEG-LS\n" + " VF.... ljpeg Lossless JPEG\n" + " VF.... magicyuv MagicYUV video\n" + " VFS... mjpeg MJPEG (Motion JPEG)\n" + " V..... mjpeg_vaapi MJPEG (VAAPI) (codec mjpeg)\n" + " V.S... mpeg1video MPEG-1 video\n" + " V.S... mpeg2video MPEG-2 video\n" + " V..... mpeg2_vaapi MPEG-2 (VAAPI) (codec mpeg2video)\n" + " V.S... mpeg4 MPEG-4 part 2\n" + " V..... libxvid libxvidcore MPEG-4 part 2 (codec mpeg4)\n" + " V..... mpeg4_v4l2m2m V4L2 mem2mem MPEG4 encoder wrapper (codec mpeg4)\n" + " V..... msmpeg4v2 MPEG-4 part 2 Microsoft variant version 2\n" + " V..... msmpeg4 MPEG-4 part 2 Microsoft variant version 3 (codec msmpeg4v3)\n" + " V..... msvideo1 Microsoft Video-1\n" + " V..... pam PAM (Portable AnyMap) image\n" + " V..... pbm PBM (Portable BitMap) image\n" + " V..... pcx PC Paintbrush PCX image\n" + " V..... pgm PGM (Portable GrayMap) image\n" + " V..... pgmyuv PGMYUV (Portable GrayMap YUV) image\n" + " VF.... png PNG (Portable Network Graphics) image\n" + " V..... ppm PPM (Portable PixelMap) image\n" + " VF.... prores Apple ProRes\n" + " VF.... prores_aw Apple ProRes (codec prores)\n" + " VFS... prores_ks Apple ProRes (iCodec Pro) (codec prores)\n" + " V..... qtrle QuickTime Animation (RLE) video\n" + " V..... r10k AJA Kona 10-bit RGB Codec\n" + " V..... r210 Uncompressed RGB 10-bit\n" + " V..... rawvideo raw video\n" + " V..... roqvideo id RoQ video (codec roq)\n" + " V..... rv10 RealVideo 1.0\n" + " V..... rv20 RealVideo 2.0\n" + " V..... sgi SGI image\n" + " V..... snow Snow\n" + " V..... sunrast Sun Rasterfile image\n" + " V..... svq1 Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1\n" + " V..... targa Truevision Targa image\n" + " V..... libtheora libtheora Theora (codec theora)\n" + " VF.... tiff TIFF image\n" + " VF.... utvideo Ut Video\n" + " V..... v210 Uncompressed 4:2:2 10-bit\n" + " V..... v308 Uncompressed packed 4:4:4\n" + " V..... v408 Uncompressed packed QT 4:4:4:4\n" + " V..... v410 Uncompressed 4:4:4 10-bit\n" + " V..... libvpx libvpx VP8 (codec vp8)\n" + " V..... vp8_v4l2m2m V4L2 mem2mem VP8 encoder wrapper (codec vp8)\n" + " V..... vp8_vaapi VP8 (VAAPI) (codec vp8)\n" + " V..... libvpx-vp9 libvpx VP9 (codec vp9)\n" + " V..... vp9_vaapi VP9 (VAAPI) (codec vp9)\n" + " V..... libwebp_anim libwebp WebP image (codec webp)\n" + " V..... libwebp libwebp WebP image (codec webp)\n" + " V..... wmv1 Windows Media Video 7\n" + " V..... wmv2 Windows Media Video 8\n" + " V..... wrapped_avframe AVFrame to AVPacket passthrough\n" + " V..... xbm XBM (X BitMap) image\n" + " V..... xface X-face image\n" + " V..... xwd XWD (X Window Dump) image\n" + " V..... y41p Uncompressed YUV 4:1:1 12-bit\n" + " V..... yuv4 Uncompressed packed 4:2:0\n" + " VF.... zlib LCL (LossLess Codec Library) ZLIB\n" + " V..... zmbv Zip Motion Blocks Video\n" + " A..... aac AAC (Advanced Audio Coding)\n" + " A..... ac3 ATSC A/52A (AC-3)\n" + " A..... ac3_fixed ATSC A/52A (AC-3) (codec ac3)\n" + " A..... adpcm_adx SEGA CRI ADX ADPCM\n" + " A..... g722 G.722 ADPCM (codec adpcm_g722)\n" + " A..... g726 G.726 ADPCM (codec adpcm_g726)\n" + " A..... g726le G.726 little endian ADPCM (\"right-justified\") (codec adpcm_g726le)\n" + " A..... adpcm_ima_qt ADPCM IMA QuickTime\n" + " A..... adpcm_ima_wav ADPCM IMA WAV\n" + " A..... adpcm_ms ADPCM Microsoft\n" + " A..... adpcm_swf ADPCM Shockwave Flash\n" + " A..... adpcm_yamaha ADPCM Yamaha\n" + " A..... alac ALAC (Apple Lossless Audio Codec)\n" + " A..... libopencore_amrnb OpenCORE AMR-NB (Adaptive Multi-Rate Narrow-Band) (codec amr_nb)\n" + " A..... aptx aptX (Audio Processing Technology for Bluetooth)\n" + " A..... aptx_hd aptX HD (Audio Processing Technology for Bluetooth)\n" + " A..... comfortnoise RFC 3389 comfort noise generator\n" + " A..X.. dca DCA (DTS Coherent Acoustics) (codec dts)\n" + " A..... eac3 ATSC A/52 E-AC-3\n" + " A..... flac FLAC (Free Lossless Audio Codec)\n" + " A..... g723_1 G.723.1\n" + " A..... libgsm libgsm GSM (codec gsm)\n" + " A..... libgsm_ms libgsm GSM Microsoft variant (codec gsm_ms)\n" + " A..X.. mlp MLP (Meridian Lossless Packing)\n" + " A..... mp2 MP2 (MPEG audio layer 2)\n" + " A..... mp2fixed MP2 fixed point (MPEG audio layer 2) (codec mp2)\n" + " A..... libmp3lame libmp3lame MP3 (MPEG audio layer 3) (codec mp3)\n" + " A..... nellymoser Nellymoser Asao\n" + " A..X.. opus Opus\n" + " A..... libopus libopus Opus (codec opus)\n" + " A..... pcm_alaw PCM A-law / G.711 A-law\n" + " A..... pcm_f32be PCM 32-bit floating point big-endian\n" + " A..... pcm_f32le PCM 32-bit floating point little-endian\n" + " A..... pcm_f64be PCM 64-bit floating point big-endian\n" + " A..... pcm_f64le PCM 64-bit floating point little-endian\n" + " A..... pcm_mulaw PCM mu-law / G.711 mu-law\n" + " A..... pcm_s16be PCM signed 16-bit big-endian\n" + " A..... pcm_s16be_planar PCM signed 16-bit big-endian planar\n" + " A..... pcm_s16le PCM signed 16-bit little-endian\n" + " A..... pcm_s16le_planar PCM signed 16-bit little-endian planar\n" + " A..... pcm_s24be PCM signed 24-bit big-endian\n" + " A..... pcm_s24daud PCM D-Cinema audio signed 24-bit\n" + " A..... pcm_s24le PCM signed 24-bit little-endian\n" + " A..... pcm_s24le_planar PCM signed 24-bit little-endian planar\n" + " A..... pcm_s32be PCM signed 32-bit big-endian\n" + " A..... pcm_s32le PCM signed 32-bit little-endian\n" + " A..... pcm_s32le_planar PCM signed 32-bit little-endian planar\n" + " A..... pcm_s64be PCM signed 64-bit big-endian\n" + " A..... pcm_s64le PCM signed 64-bit little-endian\n" + " A..... pcm_s8 PCM signed 8-bit\n" + " A..... pcm_s8_planar PCM signed 8-bit planar\n" + " A..... pcm_u16be PCM unsigned 16-bit big-endian\n" + " A..... pcm_u16le PCM unsigned 16-bit little-endian\n" + " A..... pcm_u24be PCM unsigned 24-bit big-endian\n" + " A..... pcm_u24le PCM unsigned 24-bit little-endian\n" + " A..... pcm_u32be PCM unsigned 32-bit big-endian\n" + " A..... pcm_u32le PCM unsigned 32-bit little-endian\n" + " A..... pcm_u8 PCM unsigned 8-bit\n" + " A..... pcm_vidc PCM Archimedes VIDC\n" + " A..... real_144 RealAudio 1.0 (14.4K) (codec ra_144)\n" + " A..... roq_dpcm id RoQ DPCM\n" + " A..X.. s302m SMPTE 302M\n" + " A..... sbc SBC (low-complexity subband codec)\n" + " A..X.. sonic Sonic\n" + " A..X.. sonicls Sonic lossless\n" + " A..... libspeex libspeex Speex (codec speex)\n" + " A..X.. truehd TrueHD\n" + " A..... tta TTA (True Audio)\n" + " A..X.. vorbis Vorbis\n" + " A..... libvorbis libvorbis (codec vorbis)\n" + " A..... wavpack WavPack\n" + " A..... wmav1 Windows Media Audio 1\n" + " A..... wmav2 Windows Media Audio 2\n" + " S..... ssa ASS (Advanced SubStation Alpha) subtitle (codec ass)\n" + " S..... ass ASS (Advanced SubStation Alpha) subtitle\n" + " S..... dvbsub DVB subtitles (codec dvb_subtitle)\n" + " S..... dvdsub DVD subtitles (codec dvd_subtitle)\n" + " S..... mov_text 3GPP Timed Text subtitle\n" + " S..... srt SubRip subtitle (codec subrip)\n" + " S..... subrip SubRip subtitle\n" + " S..... text Raw text subtitle\n" + " S..... webvtt WebVTT subtitle\n" + " S..... xsub DivX subtitles (XSUB)\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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