编写正则表达式以查找仅包含字母表的括号

时间:2015-09-01 09:31:15

标签: ruby-on-rails regex

考虑以下字符串,我想替换包含带空格的字母的括号:

str = (abc pqr xyz (tttt) 2018(2))

我期待以下输出:

str_op =  abc pqr xyz tttt 2018(2)

如何编写上述示例的正则表达式

1 个答案:

答案 0 :(得分:1)

@{
  ViewBag.Title = "Index";
  Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
  <link href="~/Assets/Styles/Admin/bootstrap.min.css" rel="stylesheet" />
  <link href="~/Assets/Styles/Admin/HomeIndexStyle.css" rel="stylesheet" />
  <script src="~/Assets/Js/jquery-1.11.3.min.js"></script>
  <script src="~/Assets/Js/jquery-1.11.3.js"></script>
}

@model List<Model.ADO.M_STUDENT>

@using(@Html.BeginForm()) {
  @Html.DropDownList("paging", new List<SelectListItem> {
    new SelectListItem{Text="1",Value="1"},
    new SelectListItem{Text="5",Value="5",Selected=true},
    new SelectListItem{Text="10",Value="10"}
  }, new { onchange = @"form.submit();"})
}

@{
  var webGird = new WebGrid(
    Model, rowsPerPage: ViewBag.rowsPerPage,
    defaultSort: "Update_At",
    columnNames: new[] { "ID", "Name", "Address", "Email", "Phone", "Status", "Update_By", "Update_At" }
  );
  webGird.SortDirection = SortDirection.Descending;
  @webGird.GetHtml(tableStyle: "table table-bordered table-hover table-striped")
}

您可以使用它并替换为(\([^\D]*\))|\(|\) 。请参阅演示。

https://regex101.com/r/sS2dM8/27