How to get a array of strings matched to a regex #1687
-
Hello I am trying to create a custom rule, that should match if a parameter I pass match the format for a subnet. I have tested with a string, and that seems to work. The parameter looks like this: And the Rule looks like this
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@JonasCordsen You are correct it is related to the match expression expecting a string. Try this: ---
# Synopsis:
apiVersion: github.com/microsoft/PSRule/v1
kind: Rule
recommend: 'VPN Local gateways onPremise network should be a subnet'
metadata:
name: 'Local.YAML.localNetworkGateways.Subnet'
spec:
type:
- 'Microsoft.Network/localNetworkGateways'
condition:
allOf:
- field: 'properties.localNetworkAddressSpace.addressPrefixes'
isArray: true
- field: 'properties.localNetworkAddressSpace.addressPrefixes'
allOf:
- field: .
match: '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/([1-3][0-2]$|[0-2][0-9]$|0?[0-9]$)'
|
Beta Was this translation helpful? Give feedback.
@JonasCordsen You are correct it is related to the match expression expecting a string.
Try this: