正则表达式捕获的组反向引用不起作用

时间:2019-06-18 20:05:50

标签: java regex backreference

我正在尝试使用正则表达式反向引用,但遇到了一些非常简单的情况。

正则表达式与整个输入不匹配: int iCellCount = 3; // In this example, i am defining cell count = 3 as static value. In the real time, cell count is picked from the excel file. var cellValue = string.Empty; DataTable dt = new DataTable(); DataRow row; //Create a DataRow foreach (ExcelReportCell excelCell in excelRow) // Iterating the excel cell row by row in the Excel Sheet { cellValue = excelCell.GetText().ToString(); // cellValue is assigned dynamically through excel file cell by cell iteration logic for (int i = 1; i <= iCellCount; i++) { row = dt.NewRow(); row["Your_Column_Name_Here"] = cellValue; dt.Rows.Add(row); } }

输入: ([\D\s]+)(\d+)\1

链接:https://regex101.com/r/yfFLmc/1/

另一方面,不带反向引用(但重复第一个捕获组)的同一个正则表达式正确匹配整个输入:Foo 12 bar

为什么带有反向引用的正则表达式与整个输入不匹配?

0 个答案:

没有答案