Bug 99181

Summary: CountIf ? (german: ZÄHLENWENN) with regexp does not count correctly
Product: LibreOffice Reporter: Tom <tommyads>
Component: CalcAssignee: Not Assigned <libreoffice-bugs>
Status: RESOLVED NOTABUG    
Severity: normal CC: gerard.fargeot
Priority: medium    
Version: 5.0.5.2 release   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: screenshot with formula and result in Cell K217

Description Tom 2016-04-09 14:55:16 UTC
Created attachment 124204 [details]
screenshot with formula and result in Cell K217

Formula
=ZÄHLENWENN($N217:$AD217;".*mo|mw|ma|ml|mu|my.*")

does not count cells with following content 
ml,5
(option regexp. within formulas is switched on!)

but does correctly count cells with content
ml

Something seems wrong.
Comment 1 GerardF 2016-04-09 16:57:47 UTC
The 1st .* applies only to 1st criterion "mo" and the last to "my".
Using parenthesis make the formula giving expected result :

=ZÄHLENWENN($N217:$AD217;".*(mo|mw|ma|ml|mu|my).*")
Comment 2 Tom 2016-04-09 20:15:20 UTC
Thank you!
Regexp ".*(mo|mw|ma|ml|mu|my).*" works fine! 
Hope this is explained in documentation/help ...

The following comment is not too important (as it works with the above): 
still the behaviour seems to me not intuitive.
In short: if ".*mo|mw|ma|ml|mu|my.*" matches 
ml
why does it not match
mlm
as is the case?
i.e., it only matches if the cell contains exactly ml and no character before nor any character thereafter.

So ".*mo|mw|ma|ml|mu|my.*" seems to work exactly like
"mo|mw|ma|ml|mu|my"
Comment 3 GerardF 2016-04-10 08:54:12 UTC
(In reply to Tom from comment #2)

> In short: if ".*mo|mw|ma|ml|mu|my.*" matches 
> ml
> why does it not match
> mlm
> as is the case?
> i.e., it only matches if the cell contains exactly ml and no character
> before nor any character thereafter.
> 
> So ".*mo|mw|ma|ml|mu|my.*" seems to work exactly like
> "mo|mw|ma|ml|mu|my"

No, this search matches:
.*mo
mw
ma
ml
mu
my.*

Word ending with "mo", words beginning with "my" and exact match for others.
"hel|hal.*" with find exact match "hel" and words beginning with "hal".
Operator | (or) have priority. (.* applies only to "hal".
While with "(hel|hal).*" will find "hell", "hello", "hallo", "hellish"...
(With the grouping parenthesis, ".*" apllies to all the group.)