{"id":14969268,"url":"https://github.com/cucumber/cucumber-expressions","last_synced_at":"2025-05-14T14:08:50.284Z","repository":{"id":37245991,"uuid":"408372154","full_name":"cucumber/cucumber-expressions","owner":"cucumber","description":"Human friendly alternative to Regular Expressions","archived":false,"fork":false,"pushed_at":"2025-05-08T17:35:42.000Z","size":10185,"stargazers_count":171,"open_issues_count":23,"forks_count":53,"subscribers_count":69,"default_branch":"main","last_synced_at":"2025-05-12T04:45:04.746Z","etag":null,"topics":["dotnet","go","java","javascript","polyglot-release","python","ruby","tidelift"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cucumber.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"open_collective":"cucumber","github":"cucumber"}},"created_at":"2021-09-20T08:52:59.000Z","updated_at":"2025-05-08T17:35:08.000Z","dependencies_parsed_at":"2023-12-22T00:58:56.124Z","dependency_job_id":"39431224-6418-46d5-8326-4454ff60bc55","html_url":"https://github.com/cucumber/cucumber-expressions","commit_stats":{"total_commits":2902,"total_committers":55,"mean_commits":"52.763636363636365","dds":0.6747070985527223,"last_synced_commit":"98317da475a233acf63d558f4858d54a954450cc"},"previous_names":[],"tags_count":158,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cucumber%2Fcucumber-expressions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cucumber%2Fcucumber-expressions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cucumber%2Fcucumber-expressions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cucumber%2Fcucumber-expressions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cucumber","download_url":"https://codeload.github.com/cucumber/cucumber-expressions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253825022,"owners_count":21970120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","go","java","javascript","polyglot-release","python","ruby","tidelift"],"created_at":"2024-09-24T13:41:27.876Z","updated_at":"2025-05-14T14:08:50.265Z","avatar_url":"https://github.com/cucumber.png","language":"Java","funding_links":["https://opencollective.com/cucumber","https://github.com/sponsors/cucumber"],"categories":[],"sub_categories":[],"readme":"[![test-go](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-go.yml/badge.svg)](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-go.yml)\n[![test-java](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-java.yml/badge.svg)](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-java.yml)\n[![test-javascript](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-javascript.yml/badge.svg)](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-javascript.yml)\n[![test-python](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-python.yml/badge.svg)](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-python.yml)\n[![test-ruby](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-ruby.yml/badge.svg)](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-ruby.yml)\n[![test-dotnet](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-dotnet.yml/badge.svg)](https://github.com/cucumber/cucumber-expressions/actions/workflows/test-dotnet.yml)\n\n# Cucumber Expressions\n\nCucumber Expressions is an alternative to [Regular Expressions](https://en.wikipedia.org/wiki/Regular_expression)\nwith a more intuitive syntax.\n\n[Try Cucumber Expressions in your browser](https://cucumber.github.io/try-cucumber-expressions/).\n\nCucumber supports both Cucumber Expressions and Regular Expressions for defining\n[Step Definitions](https://cucumber.io/docs/cucumber/step-definitions), but you cannot\nmix Cucumber Expression syntax with Regular Expression syntax in the same expression.\n\nOn platforms that don't have a literal syntax for regular expressions (such as Java),\nCucumber will create a Cucumber Expression by default. To use Regular Expressions, add anchors (starting with `^` and ending with `$`) or forward slashes (`/`). For more information, see\n[Cucumber Expression - Java Heuristics](https://github.com/cucumber/cucumber-expressions/blob/main/java/heuristics.adoc).\n\n## Introduction\n\nLet's write a Cucumber Expression that matches the following Gherkin step (the `Given`\nkeyword has been removed here, as it's not part of the match).\n\n    I have 42 cucumbers in my belly\n\nThe simplest Cucumber Expression that matches that text would be the text itself,\nbut we can also write a more generic expression, with an `int` *output parameter*:\n\n    I have {int} cucumbers in my belly\n\nWhen the text is matched against that expression, the number `42` is extracted\nfrom the `{int}` output parameter and passed as an argument to the [step definition](https://cucumber.io/docs/cucumber/step-definitions).\n\nThe following text would **not** match the expression:\n\n    I have 42.5 cucumbers in my belly\n\nThis is because `42.5` has a decimal part, and doesn't fit into an `int`.\nLet's change the output parameter to `float` instead:\n\n    I have {float} cucumbers in my belly\n\nNow the expression will match the text, and the float `42.5` is extracted.\n\n## Parameter types\n\nText between curly braces reference a *parameter type*. Cucumber comes with\nthe following built-in parameter types:\n\n| Parameter Type  | Description |\n| --------------- | ----------- |\n| `{int}`         | Matches integers, for example `71` or `-19`. Converts to a 32-bit signed integer if the platform supports it.|\n| `{float}`       | Matches floats, for example `3.6`, `.8` or `-9.2`. Converts to a 32 bit float if the platform supports it. |\n| `{word}`        | Matches words without whitespace, for example `banana` (but not `banana split`). |\n| `{string}`      | Matches single-quoted or double-quoted strings, for example `\"banana split\"` or `'banana split'` (but not `banana split`). Only the text between the quotes will be extracted. The quotes themselves are discarded. Empty pairs of quotes are valid and will be matched and passed to step code as empty strings. |\n| `{}` anonymous  | Matches anything (`/.*/`). |\n| `{bigdecimal}`  | Matches the same as `{float}`, but converts to a `BigDecimal` if the platform supports it. |\n| `{double}`      | Matches the same as `{float}`, but converts to a 64 bit float if the platform supports it. |\n| `{biginteger}`  | Matches the same as `{int}`, but converts to a `BigInteger` if the platform supports it. |\n| `{byte}`        | Matches the same as `{int}`, but converts to an 8 bit signed integer if the platform supports it. |\n| `{short}`       | Matches the same as `{int}`, but converts to a 16 bit signed integer if the platform supports it. |\n| `{long}`        | Matches the same as `{int}`, but converts to a 64 bit signed integer if the platform supports it. |\n\n### Java\n\n### The Anonymous Parameter\n\nThe *anonymous* parameter type will be converted to the parameter type of the step definition using an object mapper.\nCucumber comes with a built-in object mapper that can handle all numeric types as well as. `Enum`.\n\nTo automatically convert to other types it is recommended to install an object mapper. See [cucumber-java - Default Transformers](https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-java#default-transformers)\nto learn how.\n\n### Number formats\n\nJava supports parsing localised numbers. I.e. in your English feature file you\ncan format a-thousand-and-one-tenth as '1,000.1; while in French you would format it\nas '1.000,1'. \n\nParsing is facilitated by Javas [`DecimalFormat`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/text/DecimalFormat.html)\nand includes support for the scientific notation. Unfortunately the default\nlocalisation include symbols that can not be easily written on a regular\nkeyboard. So a few substitutions are made:\n\n * The minus sign is always hyphen-minus - (ascii 45).\n * If the decimal separator is a period (. ascii 46) the thousands separator is a comma (, ascii 44).\n   So '1 000.1' and '1’000.1' should always be written as '1,000.1'. \n * If the decimal separator is a comma (, ascii 44) the thousands separator is a period (. ascii 46).\n   So '1 000,1' or '1’000,1' should always be written as '1.000,1'.\n\nIf support for your preferred language could be improved, please create an issue!\n\n### Custom Parameter types\n\nCucumber Expressions can be extended so they automatically convert\noutput parameters to your own types. Consider this Cucumber Expression:\n\n    I have a {color} ball\n\nIf we want the `{color}` output parameter to be converted to a `Color` object,\nwe can define a custom parameter type in Cucumber's [configuration](https://cucumber.io/docs/cucumber/configuration).\n\nThe table below explains the various arguments you can pass when defining\na parameter type.\n\n| Argument      | Description |\n| ------------- | ----------- |\n| `name`        | The name the parameter type will be recognised by in output parameters.\n| `regexp`      | A regexp that will match the parameter. May include capture groups.\n| `type`        | The return type of the transformer.\n| `transformer` | A function or method that transforms the match from the regexp. Must have arity 1 if the regexp doesn't have any capture groups. Otherwise the arity must match the number of capture groups in `regexp`. |\n| `useForSnippets` / `use_for_snippets` | Defaults to `true`. That means this parameter type will be used to generate snippets for undefined steps. If the `regexp` frequently matches text you don't intend to be used as arguments, disable its use for snippets with `false`. |\n| `preferForRegexpMatch` / `prefer_for_regexp_match` | Defaults to `false`. Set to `true` if you have step definitions that use regular expressions, and you want this parameter type to take precedence over others during a match. |\n\n#### Java\n\n```java\n@ParameterType(\"red|blue|yellow\")  // regexp\npublic Color color(String color){  // type, name (from method)\n    return new Color(color);       // transformer function\n}\n```\n\n#### Kotlin\n\n```kotlin\n@ParameterType(\"red|blue|yellow\")   // regexp\nfun color(color: String): Color {   // name (from method), type\n    return Color(color)             // transformer function\n}                                    \n```\n\n#### Scala\n\n```scala\nParameterType(\"color\", \"red|blue|yellow\") { color: String =\u003e // name, regexp\n    Color(color)                                             // transformer function, type\n}                                    \n```\n\n#### JavaScript / TypeScript\n\n```javascript\nimport { defineParameterType } from '@cucumber/cucumber'\n\ndefineParameterType({\n    name: 'color',\n    regexp: /red|blue|yellow/,\n    transformer: s =\u003e new Color(s)\n})\n```\n\nThe `transformer` function may return a `Promise`.\n\n#### Ruby\n\n```ruby\nParameterType(\n  name:        'color',\n  regexp:      /red|blue|yellow/,\n  type:        Color,\n  transformer: -\u003e(s) { Color.new(s) }\n)\n```\n\n#### .NET / SpecFlow\n\n```CSharp\n[StepArgumentTransformation(\"(red|blue|yellow)\")]\npublic Color ConvertColor(string colorValue)\n{\n    return new Color(colorValue);\n}\n```\n\n*Note: Currently the parameter name cannot be customized, so the custom parameters can only be used with the type name, e.g. `{Color}`.*\n\n#### Python\n\n```python\nParameterType(\n  name=        \"color\",\n  regexp=      \"red|blue|yellow\",\n  type=        Color,\n  transformer= lambda s: Color(s),\n)\n```\n\n## Optional text\n\nIt's grammatically incorrect to say *1 cucumbers*, so we should make the plural **s**\noptional. That can be done by surrounding the optional text with parentheses:\n\n    I have {int} cucumber(s) in my belly\n\nThat expression would match this text:\n\n    I have 1 cucumber in my belly\n\nIt would also match this text:\n\n    I have 42 cucumbers in my belly\n\nIn Regular Expressions, parentheses indicate a capture group, but in Cucumber Expressions\nthey mean *optional text*.\n\n## Alternative text\n\nSometimes you want to relax your language, to make it flow better. For example:\n\n    I have {int} cucumber(s) in my belly/stomach\n\nThis would match either of those texts:\n\n    I have 1 cucumber in my belly\n    I have 1 cucumber in my stomach\n    I have 42 cucumbers in my stomach\n    I have 42 cucumbers in my belly\n\nAlternative text only works when there is no whitespace between the alternative parts.\n\n## Escaping\n\nIf you ever need to match `()` or `{}` literally, you can escape the\nopening `(` or `{` with a backslash:\n\n    I have {int} \\{what} cucumber(s) in my belly \\(amazing!)\n\nThis expression would match the following examples:\n\n    I have 1 {what} cucumber in my belly (amazing!)\n    I have 42 {what} cucumbers in my belly (amazing!)\n\nYou may have to escape the `\\` character itself with another `\\`, depending on your programming language.\nFor example, in Java, you have to use escape character `\\` with another backslash.\n\n    I have {int} \\\\{what} cucumber(s) in my belly \\\\(amazing!)\n\nThen this expression would match the following example:\n\n    I have 1 \\{what} cucumber in my belly \\(amazing!)\n    I have 42 \\{what} cucumbers in my belly \\(amazing!)\n\nThe `/` character will always be interpreted as an alternative, unless escaped, such as with `\\/`.\n\n## Architecture\n\nSee [ARCHITECTURE.md](ARCHITECTURE.md)\n\n## Acknowledgements\n\nThe Cucumber Expression syntax is inspired by similar expression syntaxes in\nother BDD tools, such as [Turnip](https://github.com/jnicklas/turnip),\n[Behat](https://github.com/Behat/Behat) and\n[Behave](https://github.com/behave/behave).\n\nBig thanks to Jonas Nicklas, Konstantin Kudryashov and Jens Engel for\nimplementing those libraries.\n\nThe [Tiny-Compiler-Parser tutorial](https://blog.klipse.tech/javascript/2017/02/08/tiny-compiler-parser.html)\nby [Yehonathan Sharvit](https://github.com/viebel) inspired the design of the\nCucumber expression parser.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcucumber%2Fcucumber-expressions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcucumber%2Fcucumber-expressions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcucumber%2Fcucumber-expressions/lists"}