-4

I'm looking to extract only the numbers after this "=»", but i keep having some other text too:

Regex code:

[^»]*[\d{1,}]$

Input

> login as: LOGIN SERVER@00.00.00.000's password: Last login: Thu May 23
> 15:51:49 2019 from 00.00.00.000 CREER AUTANT DE REPERTOIRES SOUS
> /NAME/NAME/NAME QU'IL Y A DE COMMERCANTS GERES. LE NOM DOIT ETRE LE NO
> DE COMMERCANT. CREER ENSUITE SOUS CHACUN D'EUX UN REPERTOIRE NAME/
> <SERVER>ps -fu NAME | grep exe | echo «resultat=»`wc -l` «resultat=»14
> <SERVER>

How do I solve this problem?

Emma
  • 27,428
  • 11
  • 44
  • 69
mz3bel
  • 59
  • 1
  • 7

2 Answers2

5

Your expression is pretty close. We might just want to have as a left boundary, then collect our digits with a ([0-9]+) and that would likely work:

=»([0-9]+)

enter image description here

RegEx

If this expression wasn't desired, it can be modified or changed in regex101.com.

RegEx Circuit

jex.im visualizes regular expressions:

enter image description here

Test

using System;
using System.Text.RegularExpressions;

public class Example
{
    public static void Main()
    {
        string pattern = @"=»([0-9]+)";
        string input = @"> login as: LOGIN SERVER@00.00.00.000's password: Last login: Thu May 23
> 15:51:49 2019 from 00.00.00.000 CREER AUTANT DE REPERTOIRES SOUS
> /NAME/NAME/NAME QU'IL Y A DE COMMERCANTS GERES. LE NOM DOIT ETRE LE NO
> DE COMMERCANT. CREER ENSUITE SOUS CHACUN D'EUX UN REPERTOIRE NAME/
> <SERVER>ps -fu NAME | grep exe | echo «resultat=»`wc -l` «resultat=»14
> <SERVER>";
        RegexOptions options = RegexOptions.Multiline;

        foreach (Match m in Regex.Matches(input, pattern, options))
        {
            Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);
        }
    }
}

Demo

const regex = /=»([0-9]+)/gm;
const str = `> login as: LOGIN SERVER@00.00.00.000's password: Last login: Thu May 23
> 15:51:49 2019 from 00.00.00.000 CREER AUTANT DE REPERTOIRES SOUS
> /NAME/NAME/NAME QU'IL Y A DE COMMERCANTS GERES. LE NOM DOIT ETRE LE NO
> DE COMMERCANT. CREER ENSUITE SOUS CHACUN D'EUX UN REPERTOIRE NAME/
> <SERVER>ps -fu NAME | grep exe | echo «resultat=»\`wc -l\` «resultat=»14
> <SERVER>`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}
Emma
  • 27,428
  • 11
  • 44
  • 69
0

Characters in square brackets mean “one of these characters”, so it's ? or » followed by a digit or { , 1 , , or } .

Positive lookbehind is the most useful here (match something that comes after X .)

(?<=something)thingIWantToMatch

So:

(?<=»)\d+

One or more digits preceded by a » , but don’t capture the »

mz3bel
  • 59
  • 1
  • 7