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

/
/
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 = "ALTER\\W.*CLUSTER\n" + "ALTER\\W.*DIMENSION\n" + "ALTER\\W.*EXTERNAL\\W.*PROCEDURE\n" + "ALTER\\W.*FULLTEXT\\W.*CATALOG\n" + "ALTER\\W.*FULLTEXT\\W.*INDEX\n" + "ALTER\\W.*FUNCTION\n" + "ALTER\\W.*INDEX\n" + "ALTER\\W.*INDEXTYPE\n" + "ALTER\\W.*LOGIN\n" + "ALTER\\W.*MATERIALIZED\\W.*VIEW\n" + "ALTER\\W.*MATERIALIZED\\W.*VIEW\\W.*LOG\n" + "ALTER\\W.*METHOD\n" + "ALTER\\W.*NICKNAME\n" + "ALTER\\W.*OPERATOR\n" + "ALTER\\W.*PACKAGE\n" + "ALTER\\W.*PARTITION\\W.*FUNCTION\n" + "ALTER\\W.*PARTITION\\W.*SCHEME\n" + "ALTER\\W.*PROCECURE\n" + "ALTER\\W.*PROCEDURE\n" + "ALTER\\W.*QUEUE\n" + "ALTER\\W.*REPLICATION\\W.*GROUP\n" + "ALTER\\W.*ROUTINE\n" + "ALTER\\W.*SEQUENCE\n" + "ALTER\\W.*SERVER\n" + "ALTER\\W.*SESSION\n" + "ALTER\\W.*TABLE\n" + "ALTER\\W.*TRIGGER\n" + "ALTER\\W.*TYPE\n" + "ALTER\\W.*USER\\W.*MAPPING\n" + "ALTER\\W.*VIEW\n" + "ALTER\\W.*XML\\W.*SCHEMA\\W.*COLLECTION\n" + "ANALYZE\n" + "BEGIN\\W.*LOGGING\n" + "BEGIN\\W.*QUERY\\W.*LOGGING\n" + "COLLECT\\W.*DEMOGRAPHICS\n" + "COLLECT\\W.*STATISTICS\n" + "COLLMOD\n" + "COMMENT\n" + "COMPACT\n" + "CREATE\\W.*ALIAS\n" + "CREATE\\W.*AUTHORIZATION\n" + "CREATE\\W.*CAST\n" + "CREATE\\W.*CLUSTER\n" + "CREATE\\W.*DATABASE\n" + "CREATE\\W.*DEFAULT\n" + "CREATE\\W.*DIMENSION\n" + "CREATE\\W.*DISTINCT\\W.*TYPE\n" + "CREATE\\W.*DUPLICATE\n" + "CREATE\\W.*ERROR\\W.*TABLE\n" + "CREATE\\W.*EXISTING\\W.*TABLE\n" + "CREATE\\W.*EXTERNAL\\W.*PROCEDURE\n" + "CREATE\\W.*EXTERNAL\\W.*TABLE\n" + "CREATE\\W.*FULLTEXT\\W.*CATALOG\n" + "CREATE\\W.*FULLTEXT\\W.*INDEX\n" + "CREATE\\W.*FUNCTION\n" + "CREATE\\W.*FUNCTION\\W.*MAPPING\n" + "CREATE\\W.*GLOBAL\\W.*TEMPORARY\\W.*TRACE\\W.*TABLE\n" + "CREATE\\W.*HASH\\W.*INDEX\n" + "CREATE\\W.*INDEX\n" + "CREATE\\W.*INDEX\\W.*EXTENSION\n" + "CREATE\\W.*JOIN\\W.*INDEX\n" + "CREATE\\W.*LIBRARY\n" + "CREATE\\W.*LOGIN\n" + "CREATE\\W.*MACRO\n" + "CREATE\\W.*MATERIALIZED\\W.*VIEW\n" + "CREATE\\W.*MATERIALIZED\\W.*VIEW\\W.*LOG\n" + "CREATE\\W.*METHOD\n" + "CREATE\\W.*NICKNAME\n" + "CREATE\\W.*OPERATOR\n" + "CREATE\\W.*OR\\W.*REPLACE\\W.*FUNCTION\n" + "CREATE\\W.*OR\\W.*REPLACE\\W.*PROCEDURE\n" + "CREATE\\W.*OR\\W.*REPLACE\\W.*TRIGGER\n" + "CREATE\\W.*OR\\W.*REPLACE\\W.*VIEW\n" + "CREATE\\W.*ORDERING\n" + "CREATE\\W.*PACKAGE\n" + "CREATE\\W.*PACKAGE\\W.*BODY\n" + "CREATE\\W.*PARATITION\\W.*SCHEME\n" + "CREATE\\W.*PARTITION\\W.*FUNCTION\n" + "CREATE\\W.*PROCEDURE\n" + "CREATE\\W.*PROFILE\n" + "CREATE\\W.*PROXY_TABLE\n" + "CREATE\\W.*PUBLIC\\W.*SYNONYM\n" + "CREATE\\W.*RECURSIVE\\W.*VIEW\n" + "CREATE\\W.*REPLICATION\\W.*GROUP\n" + "CREATE\\W.*ROLE\n" + "CREATE\\W.*ROUTINE\\W.*FROM\n" + "CREATE\\W.*RULE\n" + "CREATE\\W.*SCHEMA\n" + "CREATE\\W.*SEQUENCE\n" + "CREATE\\W.*SESSION\n" + "CREATE\\W.*SYNONYM\n" + "CREATE\\W.*TABLE\n" + "CREATE\\W.*TRANSFORM\n" + "CREATE\\W.*TRIGGER\n" + "CREATE\\W.*TYPE\n" + "CREATE\\W.*TYPE\\W.*BODY\n" + "CREATE\\W.*TYPE\\W.*MAPPING\n" + "CREATE\\W.*USER\n" + "CREATE\\W.*VIEW\n" + "CREATE\\W.*XML\\W.*SCHEMA\\W.*COLLECTION\n" + "DATABASE\n" + "DELETE\\W.*DATABASE\n" + "DELETE\\W.*STATISTICS\n" + "DELETE\\W.*USER\n" + "DESCRIBE\n" + "DIAGNOSTIC\\W.*\"VALIDATE\\W.*INDEX\"\n" + "DIAGNOSTIC\\W.*COSTPRINT\n" + "DIAGNOSTIC\\W.*DUMP\\W.*COSTS\n" + "DIAGNOSTIC\\W.*DUMP\\W.*SAMPLES\n" + "DIAGNOSTIC\\W.*HELP\\W.*COSTS\n" + "DIAGNOSTIC\\W.*HELP\\W.*PROFILE\n" + "DIAGNOSTIC\\W.*HELP\\W.*SAMPLES\n" + "DIAGNOSTIC\\W.*SET\\W.*COSTS\n" + "DIAGNOSTIC\\W.*SET\\W.*PROFILE\n" + "DIAGNOSTIC\\W.*SET\\W.*SAMPLES\n" + "DROP\n" + "DROP\\W.*ALIAS\n" + "DROP\\W.*AUTHORIZATION\n" + "DROP\\W.*CAST\n" + "DROP\\W.*CLUSTER\n" + "DROP\\W.*DATABASE\n" + "DROP\\W.*DEFAULT\n" + "DROP\\W.*DIMENSION\n" + "DROP\\W.*DUPLICATE\n" + "DROP\\W.*ERROR\\W.*TABLE\n" + "DROP\\W.*FULLTEXT\\W.*CATALOG\n" + "DROP\\W.*FULLTEXT\\W.*INDEX\n" + "DROP\\W.*FUNCTION\n" + "DROP\\W.*FUNCTION\\W.*MAPPING\n" + "DROP\\W.*HASH\\W.*INDEX\n" + "DROP\\W.*INDEX\n" + "DROP\\W.*INDEX\\W.*EXTENSION\n" + "DROP\\W.*JOIN\\W.*INDEX\n" + "DROP\\W.*LIBRARY\n" + "DROP\\W.*LOGIN\n" + "DROP\\W.*MACRO\n" + "DROP\\W.*MATERIALIZED\\W.*VIEW\n" + "DROP\\W.*MATERIALIZED\\W.*VIEW\\W.*LOG\n" + "DROP\\W.*NICKNAME\n" + "DROP\\W.*OPERATOR\n" + "DROP\\W.*ORDERING\n" + "DROP\\W.*OUTLINE\n" + "DROP\\W.*PACKAGE\n" + "DROP\\W.*PARTITION\\W.*FUNCTION\n" + "DROP\\W.*PARTITION\\W.*SCHEME\n" + "DROP\\W.*PROCEDURE\n" + "DROP\\W.*PROFILE\n" + "DROP\\W.*PUBLIC\\W.*SYNONYM\n" + "DROP\\W.*REPLICATION\\W.*GROUP\n" + "DROP\\W.*ROLE\n" + "DROP\\W.*ROUTINE\n" + "DROP\\W.*RULE\n" + "DROP\\W.*SEQUENCE\n" + "DROP\\W.*SESSION\n" + "DROP\\W.*STATISTICS\n" + "DROP\\W.*SYNONYM\n" + "DROP\\W.*TABLE\n" + "DROP\\W.*TRANSFORM\n" + "DROP\\W.*TRIGGER\n" + "DROP\\W.*TYPE\n" + "DROP\\W.*TYPE\\W.*BODY\n" + "DROP\\W.*TYPE\\W.*MAPPING\n" + "DROP\\W.*USER\n" + "DROP\\W.*VIEW\n" + "DROP\\W.*VIEW\\W.*HIERARCHY\n" + "DROP\\W.*XML\\W.*SCHEMA\\W.*COLLECTION\n" + "DUMP\\W.*EXPLAIN\n" + "EMPTYCAPPED\n" + "END\\W.*LOGGING\n" + "END\\W.*QUERY\\W.*LOGGING\n" + "GIVE\n" + "GRANT\n" + "GRANT\\W.*LOGON\n" + "HELP\n" + "HELP\\W.*CAST\n" + "HELP\\W.*COLUMN\n" + "HELP\\W.*CONSTRAINT\n" + "HELP\\W.*DATABASE\n" + "HELP\\W.*ERROR\\W.*TABLE\n" + "HELP\\W.*FUNCTION\n" + "HELP\\W.*HASH\\W.*INDEX\n" + "HELP\\W.*INDEX\n" + "HELP\\W.*JOIN\\W.*INDEX\n" + "HELP\\W.*MACRO\n" + "HELP\\W.*METHOD\n" + "HELP\\W.*PROCEDURE\n" + "HELP\\W.*REPLICATION\\W.*GROUP\n" + "HELP\\W.*SESSION\n" + "HELP\\W.*STATISTICS\n" + "HELP\\W.*TABLE\n" + "HELP\\W.*TRANSFORM\n" + "HELP\\W.*TRIGGER\n" + "HELP\\W.*TYPE\n" + "HELP\\W.*USER\n" + "HELP\\W.*VIEW\n" + "HELP\\W.*VOLATILE\\W.*TABLE\n" + "INITIATE\\W.*INDEX\\W.*ANALYSIS\n" + "INSERT\\W.*EXPLAIN\n" + "LOCK\\W.*TABLE\n" + "LOGGING\\W.*ONLINE\\W.*ARCHIVE\\W.*OFF\n" + "LOGGING\\W.*ONLINE\\W.*ARCHIVE\\W.*ON\n" + "MODIFY\\W.*DATABASE\n" + "MODIFY\\W.*PROFILE\n" + "MODIFY\\W.*USER\n" + "MOVE\\W.*TABLE\n" + "REMOVE\\W.*JAVA\n" + "RENAME\n" + "RENAME\\W.*COLUMN\n" + "RENAME\\W.*FUNCTION\n" + "RENAME\\W.*INDEX\n" + "RENAME\\W.*MACRO\n" + "RENAME\\W.*PROCEDURE\n" + "RENAME\\W.*SEQUENCE\n" + "RENAME\\W.*TABLE\n" + "RENAME\\W.*TRIGGER\n" + "RENAME\\W.*VIEW\n" + "RENAMECOLLECTION\n" + "REORG\n" + "REPLACE\\W.*AUTHORIZATION\n" + "REPLACE\\W.*CAST\n" + "REPLACE\\W.*FUNCTION\n" + "REPLACE\\W.*MACRO\n" + "REPLACE\\W.*METHOD\n" + "REPLACE\\W.*ORDERING\n" + "REPLACE\\W.*PROCEDURE\n" + "REPLACE\\W.*RECURSIVE\\W.*VIEW\n" + "REPLACE\\W.*TRANSFORM\n" + "REPLACE\\W.*TRIGGER\n" + "REPLACE\\W.*VIEW\n" + "RESTART\\W.*INDEX\\W.*ANALYSIS\n" + "REVOKE\n" + "REVOKE\\W.*LOGON\n" + "SET\\W.*ENCRYPTION\\W.*PASSWORD\n" + "SET\\W.*QUERY_BAND\n" + "SET\\W.*ROLE\n" + "SET\\W.*SESSION\n" + "SET\\W.*TIME\\W.*ZONE\n" + "SHOW\\W.*CAST\n" + "SHOW\\W.*ERROR\\W.*TABLE\n" + "SHOW\\W.*FUNCTION\n" + "SHOW\\W.*HASH\\W.*INDEX\n" + "SHOW\\W.*JOIN\\W.*INDEX\n" + "SHOW\\W.*MACRO\n" + "SHOW\\W.*METHOD\n" + "SHOW\\W.*PROCEDURE\n" + "SHOW\\W.*REPLICATION\\W.*GROUP\n" + "SHOW\\W.*TABLE\n" + "SHOW\\W.*TRIGGER\n" + "SHOW\\W.*TYPE\n" + "SHOW\\W.*VIEW\n" + "TRUNCATE\\W.*TABLE\n" + "UPDATE\\W.*DIMENSION\\W.*MEMBER"; final String string = "ALTER CLUSTER\n" + "ALTER DIMENSION\n" + "ALTER EXTERNAL PROCEDURE\n" + "ALTER FULLTEXT CATALOG\n" + "ALTER FULLTEXT INDEX\n" + "ALTER FUNCTION\n" + "ALTER INDEX\n" + "ALTER INDEXTYPE\n" + "ALTER LOGIN\n" + "ALTER MATERIALIZED VIEW\n" + "ALTER MATERIALIZED VIEW LOG\n" + "ALTER METHOD\n" + "ALTER NICKNAME\n" + "ALTER OPERATOR\n" + "ALTER PACKAGE\n" + "ALTER PARTITION FUNCTION\n" + "ALTER PARTITION SCHEME\n" + "ALTER PROCECURE\n" + "ALTER PROCEDURE\n" + "ALTER QUEUE\n" + "ALTER REPLICATION GROUP\n" + "ALTER ROUTINE\n" + "ALTER SEQUENCE\n" + "ALTER SERVER\n" + "ALTER SESSION\n" + "ALTER TABLE\n" + "ALTER TRIGGER\n" + "ALTER TYPE\n" + "ALTER USER MAPPING\n" + "ALTER VIEW\n" + "ALTER XML SCHEMA COLLECTION\n" + "ANALYZE\n" + "BEGIN LOGGING\n" + "BEGIN QUERY LOGGING\n" + "COLLECT DEMOGRAPHICS\n" + "COLLECT STATISTICS\n" + "COLLMOD\n" + "COMMENT\n" + "COMPACT\n" + "CREATE ALIAS\n" + "CREATE AUTHORIZATION\n" + "CREATE CAST\n" + "CREATE CLUSTER\n" + "CREATE DATABASE\n" + "CREATE DEFAULT\n" + "CREATE DIMENSION\n" + "CREATE DISTINCT TYPE\n" + "CREATE DUPLICATE\n" + "CREATE ERROR TABLE\n" + "CREATE EXISTING TABLE\n" + "CREATE EXTERNAL PROCEDURE\n" + "CREATE EXTERNAL TABLE\n" + "CREATE FULLTEXT CATALOG\n" + "CREATE FULLTEXT INDEX\n" + "CREATE FUNCTION\n" + "CREATE FUNCTION MAPPING\n" + "CREATE GLOBAL TEMPORARY TRACE TABLE\n" + "CREATE HASH INDEX\n" + "CREATE INDEX\n" + "CREATE INDEX EXTENSION\n" + "CREATE JOIN INDEX\n" + "CREATE LIBRARY\n" + "CREATE LOGIN\n" + "CREATE MACRO\n" + "CREATE MATERIALIZED VIEW\n" + "CREATE MATERIALIZED VIEW LOG\n" + "CREATE METHOD\n" + "CREATE NICKNAME\n" + "CREATE OPERATOR\n" + "CREATE OR REPLACE FUNCTION\n" + "CREATE OR REPLACE PROCEDURE\n" + "CREATE OR REPLACE TRIGGER\n" + "CREATE OR REPLACE VIEW\n" + "CREATE ORDERING\n" + "CREATE PACKAGE\n" + "CREATE PACKAGE BODY\n" + "CREATE PARATITION SCHEME\n" + "CREATE PARTITION FUNCTION\n" + "CREATE PROCEDURE\n" + "CREATE PROFILE\n" + "CREATE PROXY_TABLE\n" + "CREATE PUBLIC SYNONYM\n" + "CREATE RECURSIVE VIEW\n" + "CREATE REPLICATION GROUP\n" + "CREATE ROLE\n" + "CREATE ROUTINE FROM\n" + "CREATE RULE\n" + "CREATE SCHEMA\n" + "CREATE SEQUENCE\n" + "CREATE SESSION\n" + "CREATE SYNONYM\n" + "CREATE TABLE\n" + "CREATE TRANSFORM\n" + "CREATE TRIGGER\n" + "CREATE TYPE\n" + "CREATE TYPE BODY\n" + "CREATE TYPE MAPPING\n" + "CREATE USER\n" + "CREATE VIEW\n" + "CREATE XML SCHEMA COLLECTION\n" + "DATABASE\n" + "DELETE DATABASE\n" + "DELETE STATISTICS\n" + "DELETE USER\n" + "DESCRIBE\n" + "DIAGNOSTIC \"VALIDATE INDEX\"\n" + "DIAGNOSTIC COSTPRINT\n" + "DIAGNOSTIC DUMP COSTS\n" + "DIAGNOSTIC DUMP SAMPLES\n" + "DIAGNOSTIC HELP COSTS\n" + "DIAGNOSTIC HELP PROFILE\n" + "DIAGNOSTIC HELP SAMPLES\n" + "DIAGNOSTIC SET COSTS\n" + "DIAGNOSTIC SET PROFILE\n" + "DIAGNOSTIC SET SAMPLES\n" + "DROP\n" + "DROP ALIAS\n" + "DROP AUTHORIZATION\n" + "DROP CAST\n" + "DROP CLUSTER\n" + "DROP DATABASE\n" + "DROP DEFAULT\n" + "DROP DIMENSION\n" + "DROP DUPLICATE\n" + "DROP ERROR TABLE\n" + "DROP FULLTEXT CATALOG\n" + "DROP FULLTEXT INDEX\n" + "DROP FUNCTION\n" + "DROP FUNCTION MAPPING\n" + "DROP HASH INDEX\n" + "DROP INDEX\n" + "DROP INDEX EXTENSION\n" + "DROP JOIN INDEX\n" + "DROP LIBRARY\n" + "DROP LOGIN\n" + "DROP MACRO\n" + "DROP MATERIALIZED VIEW\n" + "DROP MATERIALIZED VIEW LOG\n" + "DROP NICKNAME\n" + "DROP OPERATOR\n" + "DROP ORDERING\n" + "DROP OUTLINE\n" + "DROP PACKAGE\n" + "DROP PARTITION FUNCTION\n" + "DROP PARTITION SCHEME\n" + "DROP PROCEDURE\n" + "DROP PROFILE\n" + "DROP PUBLIC SYNONYM\n" + "DROP REPLICATION GROUP\n" + "DROP ROLE\n" + "DROP ROUTINE\n" + "DROP RULE\n" + "DROP SEQUENCE\n" + "DROP SESSION\n" + "DROP STATISTICS\n" + "DROP SYNONYM\n" + "DROP TABLE\n" + "DROP TRANSFORM\n" + "DROP TRIGGER\n" + "DROP TYPE\n" + "DROP TYPE BODY\n" + "DROP TYPE MAPPING\n" + "DROP USER\n" + "DROP VIEW\n" + "DROP VIEW HIERARCHY\n" + "DROP XML SCHEMA COLLECTION\n" + "DUMP EXPLAIN\n" + "EMPTYCAPPED\n" + "END LOGGING\n" + "END QUERY LOGGING\n" + "GIVE\n" + "GRANT\n" + "GRANT LOGON\n" + "HELP\n" + "HELP CAST\n" + "HELP COLUMN\n" + "HELP CONSTRAINT\n" + "HELP DATABASE\n" + "HELP ERROR TABLE\n" + "HELP FUNCTION\n" + "HELP HASH INDEX\n" + "HELP INDEX\n" + "HELP JOIN INDEX\n" + "HELP MACRO\n" + "HELP METHOD\n" + "HELP PROCEDURE\n" + "HELP REPLICATION GROUP\n" + "HELP SESSION\n" + "HELP STATISTICS\n" + "HELP TABLE\n" + "HELP TRANSFORM\n" + "HELP TRIGGER\n" + "HELP TYPE\n" + "HELP USER\n" + "HELP VIEW\n" + "HELP VOLATILE TABLE\n" + "INITIATE INDEX ANALYSIS\n" + "INSERT EXPLAIN\n" + "LOCK TABLE\n" + "LOGGING ONLINE ARCHIVE OFF\n" + "LOGGING ONLINE ARCHIVE ON\n" + "MODIFY DATABASE\n" + "MODIFY PROFILE\n" + "MODIFY USER\n" + "MOVE TABLE\n" + "REMOVE JAVA\n" + "RENAME\n" + "RENAME COLUMN\n" + "RENAME FUNCTION\n" + "RENAME INDEX\n" + "RENAME MACRO\n" + "RENAME PROCEDURE\n" + "RENAME SEQUENCE\n" + "RENAME TABLE\n" + "RENAME TRIGGER\n" + "RENAME VIEW\n" + "RENAMECOLLECTION\n" + "REORG\n" + "REPLACE AUTHORIZATION\n" + "REPLACE CAST\n" + "REPLACE FUNCTION\n" + "REPLACE MACRO\n" + "REPLACE METHOD\n" + "REPLACE ORDERING\n" + "REPLACE PROCEDURE\n" + "REPLACE RECURSIVE VIEW\n" + "REPLACE TRANSFORM\n" + "REPLACE TRIGGER\n" + "REPLACE VIEW\n" + "RESTART INDEX ANALYSIS\n" + "REVOKE\n" + "REVOKE LOGON\n" + "SET ENCRYPTION PASSWORD\n" + "SET QUERY_BAND\n" + "SET ROLE\n" + "SET SESSION\n" + "SET TIME ZONE\n" + "SHOW CAST\n" + "SHOW ERROR TABLE\n" + "SHOW FUNCTION\n" + "SHOW HASH INDEX\n" + "SHOW JOIN INDEX\n" + "SHOW MACRO\n" + "SHOW METHOD\n" + "SHOW PROCEDURE\n" + "SHOW REPLICATION GROUP\n" + "SHOW TABLE\n" + "SHOW TRIGGER\n" + "SHOW TYPE\n" + "SHOW VIEW\n" + "TRUNCATE TABLE\n" + "UPDATE DIMENSION MEMBER"; 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