Regular Expressions 101

Community Patterns

Regex for chatbot to match & extract multiple command

1

Regular Expression
ECMAScript (JavaScript)

/
(?<prefix>(?:^|^[\s\n\t\r]+)\/(?:[\s\n\t\r]*)|(?<=[\s\n\t\r])\.:(?:[\s\n\t\r]*)|(?<=[\s\n\t\r])::(?:[\s\n\t\r]*))(?<command>[a-zA-Z0-9]+)(?:[\s\n\t\r]*)(?<arguments>[^]*?(?=(?<=[\s\n\t\r])\.:|(?<=[\s\n\t\r])::|$))
/
g

Description

Example: "/lowercase HELLO .:uppercase ::weather london"

===Match #1 prefix: / command: lowercase arguments: HELLO ===Match #2 prefix: .: command: uppercase arguments: - ===Match #3 prefix: :: command: weather arguments: london

Submitted by CietstHydroxide - 3 years ago