将ASA从ASDM迁移到FMC,包括访问策略。完成该项目的步骤之一是将网络/服务对象及其组迁移到FMC。计划通过使用regex筛选ASA对象(从ASA配置)并在REST API上运行python脚本来创建对象。现在,我目前遇到的问题是要将超过3000行的大量数据转移到FMC。
目前正在尝试开发一种regex模式,该模式可以过滤多行字符串并为REST API匹配数据。使用regex101执行此任务。使用当前正则表达式模式,我只匹配前两行的数据。我遇到的另一个问题是,并不是所有行都包含'destination eq‘,在此之后,正则表达式将匹配'port_no’。
有没有人可以帮助进行正则表达式的表达?根据当前的正则表达式,想要匹配'object-group service','service-object‘and 'destination eq’之后的数据,还是当'destination eq‘不存在的时候?
谢谢
正则表达式:
object-group service (?P<name>.+)(?:\n |.)service-object (?P<protocol>.+) destination eq (?P<port_no>\d{0,5} |\w{0,10}.+)\n要筛选的数据:
object-group service DM_INLINE_SERVICE_8
service-object tcp destination eq ldap
service-object udp destination eq syslog
service-object object kerberos5-tcp
service-object object kerberos5-udp
service-object object ldap-udp
service-object udp destination eq domain
service-object object ldap-gcs
service-object object TCP_3268
service-object object TCP_3269
service-object object TCP_445
service-object tcp-udp destination eq domain
service-object tcp destination eq ldaps
service-object udp destination eq ntp
service-object object TCP_464
object-group network DM_INLINE_NETWORK_13
network-object object IN_V030_197_memcache_01
network-object object IN_V030_198_memcache_02发布于 2019-11-04 19:26:27
如果你想匹配'object-group service','service-object‘和'destination eq’后面的数据,你可以使用一个alternation来匹配object-group service或service-object和一个可选的destination eq的非捕获组。
^\s*(?:object-group service|service-object) (.+?)(?: destination eq (\w+))?$分成部分
^ string\s*的开始匹配(?:object-group service|service-object)空白字符options(.+?)匹配空间的1和在greedy(?:组1中捕获匹配任何字符非destination eq (\w+)非捕获组2中的0+匹配空间和目标eq并捕获组中的字符
关闭
)?组并将其设置为optional$ End of stringhttps://stackoverflow.com/questions/58692205
复制相似问题