使用 RegEx 解析 WebLogic 集群
Parsing WebLogic Cluster Using RegEx
我有下面的文件,我需要从每个集群中解析出主机名和端口。
最终结果应如下所示:
主机=服务器1
端口 = 40002
但我还需要具有 FQDN 的那些
主持人=server1.unix.domain.com
端口 = 40002
我对正则表达式了解不够,无法完成此任务。
WebLogicCluster SERVER1:40002,SERVER2:40002
WebLogicCluster SERVER1:40002,SERVER3:40002
WebLogicCluster SERVER1:40002,SERVER4:40002
WebLogicCluster SERVER1:8003,SERVER5.unix.domain.com:8003
WebLogicCluster SERVER1.unix.domain.com:8007,SERVER6.unix.domain.com:8007
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER7.unix.domain.com:8011
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER8.unix.domain.com:8011
试试这个:
\W+([^:\s]+):(\d+)
分解它:
\W+
应该在服务器地址或任何其他非单词字符
之前捕获 space/comma
([^:\s]+)
会给你服务器地址
(\d+)
是端口
你可以试试这个:
/[, ][^:]+:\d+/g
我不确定这是否是你想要的:
const data = `WebLogicCluster SERVER1:40002,SERVER2:40002
WebLogicCluster SERVER1:40002,SERVER3:40002
WebLogicCluster SERVER1:40002,SERVER4:40002
WebLogicCluster SERVER1:8003,SERVER5.unix.domain.com:8003
WebLogicCluster SERVER1.unix.domain.com:8007,SERVER6.unix.domain.com:8007
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER7.unix.domain.com:8011
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER8.unix.domain.com:8011`
const parse = data => {
const regex = /(?: |,)(.*?):(\d*)/g, result = []
let temp
while (temp = regex.exec(data)){
result.push({name: temp[1], port: temp[2]})
}
return result
}
console.log(parse(data))
我有下面的文件,我需要从每个集群中解析出主机名和端口。
最终结果应如下所示:
主机=服务器1 端口 = 40002
但我还需要具有 FQDN 的那些
主持人=server1.unix.domain.com 端口 = 40002
我对正则表达式了解不够,无法完成此任务。
WebLogicCluster SERVER1:40002,SERVER2:40002
WebLogicCluster SERVER1:40002,SERVER3:40002
WebLogicCluster SERVER1:40002,SERVER4:40002
WebLogicCluster SERVER1:8003,SERVER5.unix.domain.com:8003
WebLogicCluster SERVER1.unix.domain.com:8007,SERVER6.unix.domain.com:8007
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER7.unix.domain.com:8011
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER8.unix.domain.com:8011
试试这个:
\W+([^:\s]+):(\d+)
分解它:
\W+
应该在服务器地址或任何其他非单词字符
([^:\s]+)
会给你服务器地址
(\d+)
是端口
你可以试试这个:
/[, ][^:]+:\d+/g
我不确定这是否是你想要的:
const data = `WebLogicCluster SERVER1:40002,SERVER2:40002
WebLogicCluster SERVER1:40002,SERVER3:40002
WebLogicCluster SERVER1:40002,SERVER4:40002
WebLogicCluster SERVER1:8003,SERVER5.unix.domain.com:8003
WebLogicCluster SERVER1.unix.domain.com:8007,SERVER6.unix.domain.com:8007
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER7.unix.domain.com:8011
WebLogicCluster SERVER1.unix.domain.com:8011,SERVER8.unix.domain.com:8011`
const parse = data => {
const regex = /(?: |,)(.*?):(\d*)/g, result = []
let temp
while (temp = regex.exec(data)){
result.push({name: temp[1], port: temp[2]})
}
return result
}
console.log(parse(data))