Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • 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
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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(?<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3})\\s{1,}(?<serverity>[^\\s]+)\\s{1,}\\[(?<thread>.*)\\]\\s{1}(?<message>.*)"; final String string = "2015-07-14 01:52:42,777 WARN [DeliveryProcessor-1] no.embriq.metermaid.delivery.impl.DeliveryProcessor - [PLAT:system.error] Exception thrown while processing delivery with id: id=25755,netOwner=NetOwner{code='1', name='Hafslund},from=Sun Jul 12 20:00:00 UTC 2015\n" + "org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT INTO METER_VALUE ( METER_VALUE.ID, TERMINAL_ID, METER_ID, READING_VALUE, READING_TIMESTAMP, COLLECTION_TIMESTAMP, COLLECTION_METHOD, COLLECTION_STATUS, VALUE_TYPE_CODE, READING_TYPE_CODE, BLOCKED, METER_POINT_ID, METER_IMPORT_ID, INTERVAL_MINUTES, NETOWNER_ID, VALIDATION_STATUS_CODE ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)]; ORA-01400: cannot insert NULL into (\"MDM_DST_V2\".\"METER_VALUE\".\"METER_ID\")\n" + "; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into (\"MDM_DST_V2\".\"METER_VALUE\".\"METER_ID\")\n\n" + " at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:243)\n" + " at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)\n" + " at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660)\n" + " at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:673)\n" + " at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:989)\n" + " at no.embriq.metermaid.database.dao.impl.MeterValueDAOJdbc.insertMeterValues(MeterValueDAOJdbc.java:650)\n" + " at no.embriq.metermaid.database.dao.impl.MeterValueDAOJdbc.insert(MeterValueDAOJdbc.java:524)\n" + " at sun.reflect.GeneratedMethodAccessor557.invoke(Unknown Source)\n" + " at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\n" + " at java.lang.reflect.Method.invoke(Unknown Source)\n" + " at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)\n" + " at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)\n" + " at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267)\n" + " at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)\n" + " at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)\n" + " at com.sun.proxy.$Proxy93.insert(Unknown Source)\n" + " at no.embriq.metermaid.delivery.metervalue.storage.DeliveryMeterValueStorageServiceImpl.saveNewMeterValues(DeliveryMeterValueStorageServiceImpl.java:56)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryControllerImpl.handleProcessedStates(DeliveryControllerImpl.java:356)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryControllerImpl.handleProcessedStatesForStatuses(DeliveryControllerImpl.java:600)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryControllerImpl.processDelivery(DeliveryControllerImpl.java:161)\n" + " at sun.reflect.GeneratedMethodAccessor400.invoke(Unknown Source)\n" + " at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\n" + " at java.lang.reflect.Method.invoke(Unknown Source)\n" + " at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)\n" + " at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)\n" + " at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267)\n" + " at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)\n" + " at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)\n" + " at com.sun.proxy.$Proxy107.processDelivery(Unknown Source)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryControllerSessionExecutorProxy$1.execute(DeliveryControllerSessionExecutorProxy.java:30)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryControllerSessionExecutorProxy$1.execute(DeliveryControllerSessionExecutorProxy.java:27)\n" + " at no.embriq.ams.persistence.currentuser.CurrentSessionUser.executeInSession(CurrentSessionUser.java:84)\n" + " at no.embriq.ams.persistence.currentuser.CurrentSessionUser.executeInSession(CurrentSessionUser.java:76)\n" + " at no.embriq.ams.persistence.currentuser.WrappedExecutable.run(WrappedExecutable.java:49)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryControllerSessionExecutorProxy.processDelivery(DeliveryControllerSessionExecutorProxy.java:27)\n" + " at sun.reflect.GeneratedMethodAccessor400.invoke(Unknown Source)\n" + " at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)\n" + " at java.lang.reflect.Method.invoke(Unknown Source)\n" + " at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)\n" + " at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)\n" + " at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267)\n" + " at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)\n" + " at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)\n" + " at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)\n" + " at com.sun.proxy.$Proxy107.processDelivery(Unknown Source)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryProcessor.processDeliveryTask(DeliveryProcessor.java:106)\n" + " at no.embriq.metermaid.delivery.impl.DeliveryProcessor.run(DeliveryProcessor.java:85)\n" + " at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n" + " at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n" + " at java.lang.Thread.run(Unknown Source)\n" + "Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into (\"MDM_DST_V2\".\"METER_VALUE\".\"METER_ID\")\n\n" + " at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)\n" + " at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)\n" + " at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)\n" + " at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)\n" + " at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)\n" + " at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)\n" + " at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)\n" + " at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044)\n" + " at oracle.jdbc.driver.OraclePreparedStatement.executeForRowsWithTimeout(OraclePreparedStatement.java:10143)\n" + " at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10249)\n" + " at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)\n" + " at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1005)\n" + " at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:989)\n" + " at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644)\n" + " ... 55 more\n"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); if (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