Home > Net >  Regex to match hyphen between two specific words surrounded by square brackets
Regex to match hyphen between two specific words surrounded by square brackets

Time:12-16

I need to match the following with Regex

[zabbix-frontend]

I have started with the following, but I do not know how I can capture the hyphen - and the following word and bracket

^\[zabbix

Any advice is greatly appreciated.

I have only tried this so far amongst other things, but cannot get a match on the words as above. ^\[zabbix

CodePudding user response:

Try

/\[(\w )\-(\w )\]/m

This will capture "zabbix" as one match and "frontend" as another match. If you want to capture "zabbix-frontend" then use:

/\[(\w \-\w )\]/m

CodePudding user response:

The following regular expression can be used to match only the string "[zabbix-frontend]":

/\[zabbix-frontend\]/

  • Related