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
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
Processing...

Test String

Code Generator

Generated Code

$re = '/(?<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>.*)/'; $str = '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 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") ; nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("MDM_DST_V2"."METER_VALUE"."METER_ID") at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:243) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:673) at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:989) at no.embriq.metermaid.database.dao.impl.MeterValueDAOJdbc.insertMeterValues(MeterValueDAOJdbc.java:650) at no.embriq.metermaid.database.dao.impl.MeterValueDAOJdbc.insert(MeterValueDAOJdbc.java:524) at sun.reflect.GeneratedMethodAccessor557.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy93.insert(Unknown Source) at no.embriq.metermaid.delivery.metervalue.storage.DeliveryMeterValueStorageServiceImpl.saveNewMeterValues(DeliveryMeterValueStorageServiceImpl.java:56) at no.embriq.metermaid.delivery.impl.DeliveryControllerImpl.handleProcessedStates(DeliveryControllerImpl.java:356) at no.embriq.metermaid.delivery.impl.DeliveryControllerImpl.handleProcessedStatesForStatuses(DeliveryControllerImpl.java:600) at no.embriq.metermaid.delivery.impl.DeliveryControllerImpl.processDelivery(DeliveryControllerImpl.java:161) at sun.reflect.GeneratedMethodAccessor400.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy107.processDelivery(Unknown Source) at no.embriq.metermaid.delivery.impl.DeliveryControllerSessionExecutorProxy$1.execute(DeliveryControllerSessionExecutorProxy.java:30) at no.embriq.metermaid.delivery.impl.DeliveryControllerSessionExecutorProxy$1.execute(DeliveryControllerSessionExecutorProxy.java:27) at no.embriq.ams.persistence.currentuser.CurrentSessionUser.executeInSession(CurrentSessionUser.java:84) at no.embriq.ams.persistence.currentuser.CurrentSessionUser.executeInSession(CurrentSessionUser.java:76) at no.embriq.ams.persistence.currentuser.WrappedExecutable.run(WrappedExecutable.java:49) at no.embriq.metermaid.delivery.impl.DeliveryControllerSessionExecutorProxy.processDelivery(DeliveryControllerSessionExecutorProxy.java:27) at sun.reflect.GeneratedMethodAccessor400.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:267) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy107.processDelivery(Unknown Source) at no.embriq.metermaid.delivery.impl.DeliveryProcessor.processDeliveryTask(DeliveryProcessor.java:106) at no.embriq.metermaid.delivery.impl.DeliveryProcessor.run(DeliveryProcessor.java:85) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: cannot insert NULL into ("MDM_DST_V2"."METER_VALUE"."METER_ID") at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207) at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044) at oracle.jdbc.driver.OraclePreparedStatement.executeForRowsWithTimeout(OraclePreparedStatement.java:10143) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10249) at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230) at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1005) at org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:989) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644) ... 55 more '; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php