#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
To share the current page content and settings, use the following link: