I want to do a regex search this is my data.
我想做一个正则表达式搜索这是我的数据。
a = 'Watch4net APG Event: Host/O:\ Label:OraDB Serial Number 1610f067 on Device dlpdb1 is alerted.'
Now I want to do the extraction as below.
现在我想进行如下提取。
rx = /Event: Host\/(.*) on/
arr = rx.exec(a)[1]
In the result I am getting the following
结果我得到以下内容
'O: Label:OraDB Serial Number 1610f067'
the backslash after the O:**** is getting missed. How can I print it?
O:****之后的反斜杠被错过了。我该如何打印?
Thanks in advance
提前致谢
1 个解决方案
#1
1
You'll have to find all backslashes in your data and replace them with a double backslash.
您必须在数据中找到所有反斜杠并用双反斜杠替换它们。
a = 'Watch4net APG Event: Host/O:\\ Label:OraDB Serial Number 1610f067 on Device dlpdb1 is alerted.'
Javascript is taking a single backslash as an escape character. Note that you won't be able to use javascript to double them up as it can't 'see' it to begin with, so will need to manipulate the data some other way.
Javascript采用单个反斜杠作为转义字符。请注意,您将无法使用javascript将它们加倍,因为它无法“看到”它开始,因此需要以其他方式操纵数据。
#1
1
You'll have to find all backslashes in your data and replace them with a double backslash.
您必须在数据中找到所有反斜杠并用双反斜杠替换它们。
a = 'Watch4net APG Event: Host/O:\\ Label:OraDB Serial Number 1610f067 on Device dlpdb1 is alerted.'
Javascript is taking a single backslash as an escape character. Note that you won't be able to use javascript to double them up as it can't 'see' it to begin with, so will need to manipulate the data some other way.
Javascript采用单个反斜杠作为转义字符。请注意,您将无法使用javascript将它们加倍,因为它无法“看到”它开始,因此需要以其他方式操纵数据。