Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (5.3k points)

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?

1 Answer

0 votes
by (9.5k points)

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

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 [email protected]'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}`); }); }

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 10, 2019 in RPA by noah kapoor (5.3k points)
0 votes
1 answer
asked Jul 10, 2019 in RPA by Abhishek_31 (12.7k points)
0 votes
1 answer

Browse Categories

...