Skip to content

[Bug]: MATCH with match_type 0 ignores the * and ? wildcards #1894

Open

Description

@trackoor

Description

MATCH(lookup_value, range, 0) treats * and ? as literal characters, so MATCH("b*", A1:A3, 0) returns #N/A. In Excel, wildcards work in MATCH with match_type 0. In HyperFormula they already work in VLOOKUP, HLOOKUP, XLOOKUP (match_mode 2), and COUNTIF, so INDEX/MATCH and VLOOKUP disagree on the same data.

const { HyperFormula } = require('hyperformula')

const hf = HyperFormula.buildFromArray([
  ['apple', '=MATCH("b*", A1:A3, 0)', '=MATCH("?ig", A1:A3, 0)', '=VLOOKUP("b*", A1:A3, 1, 0)', '=COUNTIF(A1:A3, "b*")'],
  ['banana'],
  ['fig'],
], { licenseKey: 'gpl-v3' })

console.log(hf.getSheetValues(0)[0].slice(1).map(v => v?.value ?? v))

Actual: [ '#N/A', '#N/A', 'banana', 1 ]

Expected (Excel, LibreOffice): [ 2, 3, 'banana', 1 ]

Cause: LookupPlugin.doMatch in hyperformula/src/interpreter/plugin/LookupPlugin.ts calls searchStrategy.find directly instead of this.searchInRange(..., type === 0, ...), whereas doVlookup, doHlookup, and doXlookup go through searchInRange to run the wildcard matcher.

Excel reference: https://support.microsoft.com/en-us/office/match-function-e8dffd45-c762-47d6-bf89-533f4a37673a ("If match_type is 0 and lookup_value is a text string, you can use the wildcard characters")

Video or screenshots

N/A

Demo

https://gist.github.com/trackoor/97f7755f0b12f44c2904ded4d27ff59a

HyperFormula version

3.5.0 (npm), also develop at 5a6eb09 and master at 187dfa1

Your framework

None (Node.js)

Your environment

Node.js 26.13.0, Linux

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions