It was not the place neither the object of my post, but why not. Not sure it will interest anyone here, but here it is :

C++
int counter=0; int counter2=0; regex MyRegex("123456$"); string ligne; ifstream file("10-million-combos.txt" ); if (file.is_open()) { while (getline(file,line)) { ++counter; if(regex_search(line,MyRegex)) { ++counter2; } }
Pascal/Delphi
RegexObj := TRegExpr.Create; RegexObj.Expression := '123456$'; reset(tfIn); while not eof(tfIn) do begin readln(tfIn, s); if RegexObj.Exec(s) then counter2:=counter2+1; counter:=counter+1; end;
PS
$f = [System.IO.File]::OpenText("10-million-combos.txt") while (! $f.EndOfStream) { $line = $f.ReadLine(); if ($line -match "123456$" ) { $counter +=1 } $counter2+=1 }
Py
with open("10-million-combos.txt", encoding="cp850") as infile: for line in infile: counter2 += 1 if re.search('123456$', line): counter += 1
Rb (not give he right numbers)
open("10-million-combos_LF.txt") do |content| content.each_line do |line| counter=counter+1 if line.match(/123456$/) counter2 += 1 end end end
VB.net
Dim mStreamReader As StreamReader = New StreamReader("10-million-c +ombos.txt") line = mStreamReader.ReadLine() Do While (line IsNot Nothing) counter += 1 If Regex.IsMatch(line, "123456$") Then counter2 += 1 line = mStreamReader.ReadLine() Loop
VBS
Set objTextFile = objFSO.OpenTextFile("10-million-combos.txt", For +Reading) Set objRegEx = CreateObject("VBScript.RegExp") objRegEx.Pattern = "123456$" Count=0 Count2=0 Do Until objTextFile.AtEndOfStream Count2=Count2+1 strNextLine = objTextFile.ReadLine Set colMatches = objRegEx.Execute(strNextLine) Count=Count+colMatches.Count Loop
C#
Regex rgx = new Regex("123456$"); int counter = 0; int counter2 = 0; using (StreamReader sr = new StreamReader(@"10-million-combos.txt" +)) { String line; while ((line = sr.ReadLine()) != null) { ++counter; if (rgx.IsMatch(line)) { ++counter2; } } }
PHP
$counter=0; $counter2=0; $handle = fopen("10-million-combos.txt", "r"); while (($line = fgets($handle)) !== false) { ++$counter; if(preg_match('/123456\R$/',$line)) { ++$counter2; } }
Java
String line; Pattern p = Pattern.compile("123456$"); String fichier ="10-million-combos.txt"; InputStream ips=new FileInputStream(file); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); while ((line=br.readLine())!=null){ m = p.matcher(line); if (m.find()) {count2+=1;} count+=1; }

In reply to Re^5: How to optimize a regex on a large file read line by line ? by John FENDER
in thread How to optimize a regex on a large file read line by line ? by John FENDER

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.