如何在引号内匹配搜索词

时间:2016-12-13 16:58:05

标签: javascript regex string search

我正在尝试解析搜索字词。搜索词是一个长字符串,例如:

label:none author:@root label:~"To+Do" label:~'"test me"' label:~"No Label" label:~'won"t fix' this is a search term

我正在尝试将其解析为单个键值对:

[{label: "none"}, {author:"@root"}, {label:"~\"To+Do\""}, {label: "~"test me\""}, {label: "~\"No Label\""}, {label: "~won\"t fix"}, {search: "this is a search term"}]

搜索字词是没有键的最后一项。如果搜索条件有空格,则用引号括起来。

我开始解析这个:

(label:.*?|author:.*?|milestone:.*?)

我不确定这是否有效,但我也对如何获得最后一个搜索词感到困惑。甚至不确定这是否可行。

最大的问题是引用的东西,我不知道如何匹配引用的东西。最后我要做的是用空格分割一个字符串,而忽略空格周围的引号。

我将@用于作者,~用于标记,%用于里程碑。

1 个答案:

答案 0 :(得分:2)

这似乎有用......我还将输出结构转换为更容易使用的东西:



private void dataGridView1_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = Color.Blue;
}




相关问题