Skip to content

Extracting parts from regular expression when pattern matching with switch #1820

@johndeighan

Description

@johndeighan

I was looking at the comments in another issue and found this suggestion:

switch a
  m := /(\d)/
    return m[1]

as a way of getting at groups within a matching regular expression.

I'm currently trying this, but it doesn't work:

switch a
  m^ /(\d)/
    return m

I thought that the result of the match would be assigned to the variable m
Your docs for pattern matching doesn't have examples of getting either the matched string or a subgroup from a regular expression.

Your docs need more (simple) examples of using regular expressions when pattern matching.
Meanwhile, is there any way to accomplish this using a switch statement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions