我试图在tableau中使用REGEXP_MATCH,REGEXP_EXTRACT函数来隔离指定的端口'来自数据集。
我有一个糟糕的时间,有一个领先的条目' - ',我已经尝试了以下,我能得到的最好的是4位数与领先" - & #34;,我不想要。我希望它返回数字位数,其数字符合该条件。
第一个解决方案:
(\d*-\d*)*
第二个解决方案:
(\d*-(\d*-\d*-\d*-\d*))
第三种解决方案(仅返回' 1-1-1-1'格式,匹配为-1-1-1-1):
([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})
数据样本:
NETWORK-1-1-1-1
ACCESS-1-1-1-1
FA0/1
GE-0/2/3
XE-2/1/10
GI0/0/1
GIGABIT ETHERNET 1-1-2
1-1-2-100
1-1-2-10.943
期望的隔离(粗体)
NETWORK-的 1-1-1-1
访问 - 的 1-1-1-1
FA0 / 1
GE-0/2/3
XE-2 /10分之1
GI0 / 0/1
GIGABIT ETHERNET 1-1-2
的 1-1-2-100
的 1-1-2-10 0.943
期望的回归
1-1-1-1
1-1-1-1
excluded
excluded
excluded
excluded
1-1-2
1-1-2-100
1-1-2-10
具有正则表达式匹配和提取的Tableau公式:
IF REGEXP_MATCH([Port Access Less VLAN],'(\d{0,3}\/\d{0,3}\/\d{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(\d{0,3}\/\d{0,3}\/\d{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'(\d{0,3}\/\d{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(\d{0,3}\/\d{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
ELSE NULL
END
Tableau结果:
1-1-1-1
1-1-1-1
0/1
0/2/3
2/1/10
0/0/1
1-1-2
1-1-2-100
1-1-2-10
答案 0 :(得分:0)
您应该使用{1,3}
代替{0,3}
。
答案 1 :(得分:0)
通过Wiktor的DM获得解决方案,效果很好
(\d+(-\d+)+)
以前的代码
IF REGEXP_MATCH([Port Access Less VLAN],'(\d{0,3}\/\d{0,3}\/\d{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(\d{0,3}\/\d{0,3}\/\d{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'(\d{0,3}\/\d{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(\d{0,3}\/\d{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3}-[0-9]{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'([0-9]{0,3}-[0-9]{0,3})')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'(-[0-9]{0,3})')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(-[0-9]{0,3})')
ELSE NULL
END
新的改进和工作代码
IF REGEXP_MATCH([Port Access Less VLAN],'(\d+(\/\d+)+)')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(\d+(\/\d+)+)')
ELSEIF REGEXP_MATCH([Port Access Less VLAN],'(\d+(-\d+)+)')
THEN REGEXP_EXTRACT([Port Access Less VLAN],'(\d+(-\d+)+)')
ELSE NULL
END