正则表达式以查找字母数字ID

时间:2015-11-10 11:21:23

标签: javascript regex

我想从此字符串中提取ID,即SS12345687654321AAA12345

["EMP_ID eq 'SS123456","EMP_ID eq '87654321","EMP_ID eq 'AAA12345"]

如何使用正则表达式执行此操作?

2 个答案:

答案 0 :(得分:1)

如果字符串始终采用相同的形式,您不需要正则表达式 - 您可以拆分共同的using System; using System.Windows; namespace WpfApplication.DataBinding { public partial class DataContextSample : Window { public DataContextSample() { InitializeComponent(); this.DataContext = new YourViewModel(); } } }

eq '

您的数据看起来有点奇怪,因为ID有一个开头,但没有关闭单引号。如果它们要在ID周围加上引号,那么一个简单的正则表达式将起作用:

var ids = data.map(function(entry) {
  return entry.split("eq '")[1]
})

答案 1 :(得分:0)

如果您匹配单引号区域内的数组中的标记,并且结束引用是可选的:

["EMP_ID eq 'SS123456","EMP_ID eq '87654321","EMP_ID eq 'AAA12345"].map(function(input){
   var match = input.match(/'(.+)'?/);
   return (match[1]);
});
相关问题