正则表达式可过滤掉特定字符串后面的特征

时间:2019-04-05 07:52:01

标签: regex powershell

这不是我关于正则表达式的第一个问题,但是我一直在努力使这些表达式能够按我的意图工作。

我有一排带有不同信息的结构化文本。我只想保留两个特征Connector:E_DE_HH:

让我提供示例文本行:

[10:26:33]: Connector: 8965 Info1: 8 Info2: 8 Info3: 4 E_DE_HH: 6000 Info4: 99

输出应为:

8965 6000

哪个表达式可以为我提供正确的输出?我试图替换除命名特性背后的数据以外的所有内容,但过滤掉所有内容。我对这些表达感到困惑。

谢谢您的帮助!

2 个答案:

答案 0 :(得分:1)

您的过滤器可能是:.* Connector: ([0-9]*) .* E_DE_HH: ([0-9]*) .*,而您的替换对象是:\1 \2

有关示例,请参见此regex101

答案 1 :(得分:1)

您可以在字符串上使用class TabOne(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) self.SetSize((400, 300)) self.window_1 = wx.SplitterWindow(self, wx.ID_ANY) il = wx.ImageList(16,16) self.fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16,16))) self.fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, (16,16))) self.fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, (16,16))) self.tree = wx.TreeCtrl(self.window_1, style=wx.TR_DEFAULT_STYLE | wx.TR_EDIT_LABELS) self.tree.AssignImageList(il) root = self.tree.AddRoot("Server") self.tree.SetItemData(root, None) self.tree.SetItemImage(root, self.fldridx,wx.TreeItemIcon_Normal) self.tree.SetItemImage(root, self.fldropenidx,wx.TreeItemIcon_Expanded) tree = ["A","B","C","D","E","F","G","H"] self.AddTreeNodes(root, tree) self.tree.Expand(root) self.window_1_pane_2 = wx.Panel(self.window_1, wx.ID_ANY) self.window_1.SetMinimumPaneSize(20) self.window_1.SplitVertically(self.tree, self.window_1_pane_2) sizer_1 = wx.BoxSizer(wx.HORIZONTAL) sizer_1.Add(self.window_1, 1, wx.EXPAND, 0) self.SetSizer(sizer_1) def AddTreeNodes(self, parentItem, items): for item in items: if type(item) == str: newItem = self.tree.AppendItem(parentItem, item) self.tree.SetItemData(newItem, None) #self.tree.SetItemImage(newItem, self.fileidx,wx.TreeItemIcon_Normal) else: newItem = self.tree.AppendItem(parentItem, item[0]) self.tree.SetItemPyData(newItem, None) #self.tree.SetItemImage(newItem, self.fldridx,wx.TreeItemIcon_Normal) self.tree.SetItemImage(newItem, self.fldropenidx,wx.TreeItemIcon_Expanded) self.AddTreeNodes(newItem, item[1]) 运算符,然后使用-match变量替换匹配的组。

$matches