Loading...
Regex Generator loading...

Regex Generator

Creating regular expressions is easy again!

1

Paste a sample text.
Give us an example of the text you want to match using your regex. We will provide you with some ideas how to build a regular expression.

2

Which parts of the text are interesting for you?
2020-03-12T13:34:56.123Z INFO [org.example.Class]: This is a #simple #logline containing a 'value'.
Click on the marked suggestions to select them for your regular expression.

3

4

Regular Expression
2020-03-12T13:34:56\.123Z INFO \[org\.example\.Class\]: This is a #simple #logline containing a 'value'\.
Hover the generated regular expression to see more information.

5

#include <regex.h>

int useRegex(char* textToCheck) {
    regex_t compiledRegex;
    int reti;
    int actualReturnValue = -1;
    char messageBuffer[100];

    /* Compile regular expression */
    reti = regcomp(&compiledRegex, "2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a 'value'\\.", REG_EXTENDED | REG_ICASE);
    if (reti) {
        fprintf(stderr, "Could not compile regex\n");
        return -2;
    }

    /* Execute compiled regular expression */
    reti = regexec(&compiledRegex, textToCheck, 0, NULL, 0);
    if (!reti) {
        puts("Match");
        actualReturnValue = 0;
    } else if (reti == REG_NOMATCH) {
        puts("No match");
        actualReturnValue = 1;
    } else {
        regerror(reti, &compiledRegex, messageBuffer, sizeof(messageBuffer));
        fprintf(stderr, "Regex match failed: %s\n", messageBuffer);
        actualReturnValue = -3;
    }

    /* Free memory allocated to the pattern buffer by regcomp() */
    regfree(&compiledRegex);
    return actualReturnValue;
}
using System;
using System.Text.RegularExpressions;

public class Sample
{
    public static bool useRegex(String input)
    {
        const Regex regex = new Regex("2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a 'value'\\.", RegexOptions.IgnoreCase);
        return regex.IsMatch(input);
    }
}
package main

import (
	"regexp"
)

func useRegex(s string) bool {
	re := regexp.MustCompile("(?i)2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a 'value'\\.")
	return re.MatchString(s)
}

grep on mac OS does not support option -P (for Perl regex). To make it work, install a better grep (e.g. brew install grep). Most regex will work without -P.

grep -P -i '2020-03-12T13:34:56\.123Z INFO  \[org\.example\.Class\]: This is a #simple #logline containing a '"'"'value'"'"'\.' [FILE...]
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class Sample {
    public static boolean useRegex(final String input) {
        // Compile regular expression
        final Pattern pattern = Pattern.compile("2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a 'value'\\.", Pattern.CASE_INSENSITIVE);
        // Match regex against input
        final Matcher matcher = pattern.matcher(input);
        // Use results...
        return matcher.matches();
    }
}
function useRegex(input) {
    let regex = /2020-03-12T13:34:56\.123Z INFO  \[org\.example\.Class\]: This is a #simple #logline containing a 'value'\./i;
    return regex.test(input);
}
fun useRegex(input: String): Boolean {
    val regex = Regex(pattern = "2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a 'value'\\.", options = setOf(RegexOption.IGNORE_CASE))
    return regex.matches(input)
}
<?php
function useRegex($input) {
    $regex = '/2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a \'value\'\\./i';
    return preg_match($regex, $input);
}
?>
import re

def use_regex(input_text):
    pattern = re.compile(r"2020-03-12T13:34:56\.123Z INFO  \[org\.example\.Class\]: This is a #simple #logline containing a 'value'\.", re.IGNORECASE)
    return pattern.match(input_text)
def use_regex(input)
    regex = Regexp.new('2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a \'value\'\\.', Regexp::IGNORECASE)
    regex.match input
end
func useRegex(for text: String) -> Bool {
    let regex = try! NSRegularExpression(pattern: "2020-03-12T13:34:56\\.123Z INFO  \\[org\\.example\\.Class\\]: This is a #simple #logline containing a 'value'\\.", options: [.caseInsensitive])
    let range = NSRange(location: 0, length: text.count)
    let matches = regex.matches(in: text, options: [], range: range)
    return matches.first != nil
}
Imports System.Text.RegularExpressions

Public Module Sample
    Public Function useRegex(ByVal input As String) As Boolean
        Dim regex = New Regex("2020-03-12T13:34:56\.123Z INFO  \[org\.example\.Class\]: This is a #simple #logline containing a 'value'\.", RegexOptions.IgnoreCase)
        Return regex.IsMatch(input)
    End Function
End Module
Please note that these code samples are automatically generated. They are not guaranteed to work. If you find a syntax error, please submit a bug report.
By default, all major regex engines match in case-sensitive mode. If you want patterns such as Name: [a-z]+ to match in case-insensitive fashion, we need to turn that feature on.*
By default, the dot . doesn't match line break characters such as line feeds and carriage returns. If you want patterns such as BEGIN .*? END to match across lines, we need to turn that feature on.*
By default, most major engines (except Ruby), the anchors ^ and $ only match (respectively) at the beginning and the end of the string. In other engines, if you want patterns such as ^Define and >>>$ to match (respectively) at the beginning and the end of each line, we need to turn that feature on.*
Share

To share the current page content and settings, use the following link:

Buy Me A Coffee