Regex Help

1. Enter the string that you want to use a regular expression on:


2. Select the elements that you want to extract to run regular expression generator:

u
     
s
     
e
     
r
     
      
      
      
      
@
     
l
     
o
     
c
     
a
     
l
     
h
     
o
     
s
     
t
     
      
      
      
      
email   
_
c _
ws_
[
c [
2
c 2
d2
month2
0
c 0
d
month02
2
c 2
d2
3
c 3
d3
month3
day23
w2023
int2023
real_number2023
alphanumeric2023
year2023
-
c -
0
c 0
d
8
c 8
d8
w08
int08
real_number08
alphanumeric08
day08
month08
-
c   
0
     
      
8
     
      
      
      
   08
alphanumeric08
day08
month08
yyyy-mm-dd2023-08-08
]
c ]
square_brackets[2023-08-08]
$
c $
_
c _
ws_
p
c p
i
c i
n
c n
g
c g
wping
var_nameping
wordping
alphanumericping
_
c _
ws_
1
c 1
d1
month1
2
c 2
d2
month2
7
c 7
d7
month7
day27
w127
int127
alphanumeric127
.
c .
0
     
      
d   
int
alphanumeric
day
decimal127.0
real_number127.0
.
c .
decimal.0
0
c 0
w
d
int
alphanumeric
day
.
c .
1
c 1
w1
d1
int1
alphanumeric1
day1
month1
decimal.1
real_number0.1
ip_v4127.0.0.1

Regex: ([a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+|(\[([0-9]{1,3}(\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})\])))([A-Za-z0-9]+).*?(.)(\d+).*?(\d)

Passed Regular expression test

Matches:

  • user@localhost [2023-0

3. Generated regular expression program that extracts the selected elements from the entered string:


<?php
    // Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
    // This code is generated from: 
    // https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62
    //

    $txt = "user@localhost [2023-08-08]\$ ping 127.0.0.1";
	$re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
	$re1 = "([A-Za-z0-9]+)";
	$re2 = ".*?";
	$re3 = "(.)";
	$re4 = "(\\d+)";
	$re5 = ".*?";
	$re6 = "(\\d)";
    $pattern = "/".$re0.$re1.$re2.$re3.$re4.$re5.$re6."/i";
    echo "<pre>";
    echo "Result for matching {$txt} against {$pattern}:\n";     
    
    if (preg_match_all ($pattern, $txt, $matches)) {
        print_r($matches);
        $match_count = count($matches[1]);
        for ($i = 0; $i < $match_count; $i++) {
            $str = $matches[1][$i];
            //$pos = $matches[1][$i];
            echo "* Found ($str) \n";
            
        }
    }
    echo "</pre>";
    // Paste the code into a new php file. Then in your console:
    // $ php x.php   
?>

#!/usr/bin/perl
# Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
# URL that generated this code:
# https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62

    $txt = "user\@localhost [2023-08-08]\$ ping 127.0.0.1";      
	$re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+\@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
	$re1 = "([A-Za-z0-9]+)";
	$re2 = ".*?";
	$re3 = "(.)";
	$re4 = "(\\d+)";
	$re5 = ".*?";
	$re6 = "(\\d)";
    $pattern = $re0.$re1.$re2.$re3.$re4.$re5.$re6;
    if ($txt =~ m/$pattern/i)
    {
        $int1=$1;
        print "($int1) \n";
    }
#-----
# Paste the code into a new perl file. Then in Unix:
# $ perl x.pl 
#-----

// Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
// This code is generated from: 
// https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62
//
#include <iostream>
#include <string>
#include <regex>
#include <stdlib.h>

using namespace std;

int main() {
    string txt = "user@localhost [2023-08-08]$ ping 127.0.0.1";
	string re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
	string re1 = "([A-Za-z0-9]+)";
	string re2 = ".*?";
	string re3 = "(.)";
	string re4 = "(\\d+)";
	string re5 = ".*?";
	string re6 = "(\\d)";
    string pattern = re0 + re1 + re2 + re3 + re4 + re5 + re6;

    regex reg(pattern, regex_constants::icase);
    smatch match;

    if (regex_search(txt, match, reg)) {
        string int1 = match[1].str();
        cout << "(" << int1 << ")" << endl;
    }

    return 0;
} 

//-----
// Reference: // http://en.cppreference.com/w/cpp/regex
//
// Compile and run on Unix using 
// # c++ x.cpp 
// # ./a.out
// 

// Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
// This code is generated from: 
// https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62
//
import java.util.regex.*;
class Main
{
  public static void main(String[] args)
  {
    String txt="user@localhost [2023-08-08]$ ping 127.0.0.1";
	string re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
	string re1 = "([A-Za-z0-9]+)";
	string re2 = ".*?";
	string re3 = "(.)";
	string re4 = "(\\d+)";
	string re5 = ".*?";
	string re6 = "(\\d)";
    string pattern = re0 + re1 + re2 + re3 + re4 + re5 + re6;
    
    Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher m = p.matcher(txt);
    if (m.find())
    {
        String int1=m.group(1);
        System.out.print("("+int1.toString()+")"+"\n");
    }
  }
}
//-----
// This code is for use with Java VM - see https://openjdk.org for downloads. 
//
// Paste the code into a new java application or a file called 'Main.java'
//
// Compile and run in Unix using:
// # javac Main.java 
// # java Main 
//

// Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
// This code is generated from: 
// https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62
//
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplication1;

class Program
{

  public static bool useRegex(String input)
  {
      const Regex regex = new Regex("%1\$s"%2\$s);
      return regex.IsMatch(input);
  }

  static void Main(string[] args)
  {
    string txt = "user@localhost [2023-08-08]$ ping 127.0.0.1";
  	string re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
	string re1 = "([A-Za-z0-9]+)";
	string re2 = ".*?";
	string re3 = "(.)";
	string re4 = "(\\d+)";
	string re5 = ".*?";
	string re6 = "(\\d)";
    string pattern = re0 + re1 + re2 + re3 + re4 + re5 + re6;

    Regex r = new Regex(pattern,);
    Match m = r.Match(txt);
    if (m.Success)
    {
          String int1 = m.Groups[1].ToString();
          Console.Write("(" + int1.ToString() + ")"+"\n");
    }
    Console.ReadLine();
  }
}

//-----
// Paste the code into a new Console Application
//-----

' Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
' Generated automatically from the following URL:
' https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62
Imports System.Text.RegularExpressions

Module Main
    Sub Main()
        Dim txt As String = "user@localhost [2023-08-08]\$ ping 127.0.0.1"

	Dim re0 As String = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))"
	Dim re1 As String = "([A-Za-z0-9]+)"
	Dim re2 As String = ".*?"
	Dim re3 As String = "(.)"
	Dim re4 As String = "(\\d+)"
	Dim re5 As String = ".*?"
	Dim re6 As String = "(\\d)"

        Dim pattern As String = re0 & re1 & re2 & re3 & re4 & re5 & re6

        Dim regex As New Regex(pattern, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
        Dim match As Match = regex.Match(txt)

        If match.Success Then
            Dim int1 As String = match.Groups(1).Value
            Console.WriteLine("(" & int1 & ")")
        End If
    End Sub
End Module

// Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
// This code is generated from: 
// https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62
//
program Main;

uses
  RegExpr;

var
  txt, pattern, re0, re1, re2, re3, re4, re5, re6 : string;
  regex: TRegExpr;
  int1: string;

begin
  txt := 'user@localhost [2023-08-08]$ ping 127.0.0.1';
  re0 := '([a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~'']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.?)+|(\[([0-9]{1,3}(\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})\])))';
  re1 := '([A-Za-z0-9]+)';
  re2 := '.*?';
  re3 := '(.)';
  re4 := '(\d+)';
  re5 := '.*?';
  re6 := '(\d)';
  pattern := re0 + re1 + re2 + re3 + re4 + re5 + re6;

  regex := TRegExpr.Create;
  regex.ModifierI := True;  // Enable case-insensitive matching

  regex.Expression := pattern;

  if regex.Exec(txt) then
  begin
    int1 := regex.Match[1];
    WriteLn('(', int1, ')');
  end;

  regex.Free;
end.

#!/usr/bin/python
# Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
# Generated automatically from the following URL:
# https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62

import re

txt = "user@localhost [2023-08-08]$ ping 127.0.0.1"
re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
re1 = "([A-Za-z0-9]+)";
re2 = ".*?";
re3 = "(.)";
re4 = "(\\d+)";
re5 = ".*?";
re6 = "(\\d)";
pattern = re0 + re1 + re2 + re3 + re4 + re5 + re6;
rg = re.compile(pattern, re.IGNORECASE | re.DOTALL)
m = rg.search(txt)
if m:
    int1 = m.group(1)
    print ("("+int1+")"+"\n")
    
#-----
# Paste the code into a new python file. Then execute:
# $ python3 test.py 
#-----

#!/usr/bin/ruby
# Please note that this regex generator is still in BETA (v0.9BETA). If there's an error, please click the Bug Report button on the site
# Generated automatically from the following URL:
# https://www.txt2regex.com/generator/?txt=user%40localhost+%5B2023-08-08%5D%24+ping+127.0.0.1&sel=15%2C101%2C6%2C61%2C57%2C-62

txt = "user@localhost [2023-08-08]$ ping 127.0.0.1"
re0 = "([a-zA-Z0-9_\\-\\.\\+\\^!#\\$%&*+\\/\\=\\?\\`\\|\\{\\}~']+@((?:(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.?)+|(\\[([0-9]{1,3}(\\.[0-9]{1,3}){3}|[0-9a-fA-F]{1,4}(\\:[0-9a-fA-F]{1,4}){7})\\])))";
re1 = "([A-Za-z0-9]+)";
re2 = ".*?";
re3 = "(.)";
re4 = "(\\d+)";
re5 = ".*?";
re6 = "(\\d)";
pattern = re0 + re1 + re2 + re3 + re4 + re5 + re6;

m=Regexp.new(pattern, Regexp::IGNORECASE);
if m.match(txt)
    int1=m.match(txt)[1];
    puts "("<<int1<<")"<< "\n"
end
#-----
# Paste the code into a new ruby file. Then execute:
# $ ruby test.ruby
#-----