Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello

I want to extract string with regex my string is <ch.syslogged>firmNb=2&documentNb=36729&type=invoiceDebtor&customerNb=10

and I want one time 36729 one another time 10 and one another time invoiceDebtor

can you help me ?

thanks

Hello, I want to extract string with regex my string is <ch.syslogged>firmNb=2&documentNb=36729&type=invoiceDebtor&customerNb=10

and I want one time 36729 one another time 10 and one another time invoiceDebtor

can you help me ?


What I have tried:

I try this
.*documentNb=(.*)&type(.*)
but i retrieve the all string and I only want the group 1
Posted
Updated 17-Jan-23 3:29am

1 solution

Try this:
C#
private void MyButton_Click(object sender, EventArgs e)
    {
    string inp = "< ch.syslogged > firmNb = 2 & documentNb = 36729 & type = invoiceDebtor & customerNb = 10";
    string pat = ".*documentNb\\s*=\\s*(?<docNb>\\d+).*?customerNb\\s*=\\s*(?<custNb>\\d+)";
    Match m = Regex.Match(inp, pat);
    if (m.Success)
        {
        Console.WriteLine($"{m.Groups["docNb"]}:{m.Groups["custNb"]}");
        }
    }
If you are going to use regular expressions, you need a helper tool. Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900