Google表格:REGEXREPLACE匹配除特定模式以外的所有内容 [英] Google sheet : REGEXREPLACE match everything except a particular pattern

查看:89
本文介绍了Google表格:REGEXREPLACE匹配除特定模式以外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会尝试替换此字符串中的所有内容:

I would try to replace everything inside this string :


[JGMORGAN-BANK2] n°10 NEWYORK,n°222 CAEN, MONTELLIER,VANNES / TARARTA TIs
1303222074、1403281851& 1307239335 et Cloture TIs 1403277567,
1410315029

[JGMORGAN - BANK2] n° 10 NEWYORK, n° 222 CAEN, MONTELLIER, VANNES / TARARTA TIs 1303222074, 1403281851 & 1307239335 et Cloture TIs 1403277567, 1410315029

除了以下数字:
1303222074
1403281851
1307239335
1403277567
1410315029

Except the following numbers : 1303222074 1403281851 1307239335 1403277567 1410315029

我建立了一个正则表达式来匹配它们:

I have built a REGEX to match them :

1[0-9]{9}

但是我还没有想出要做相反的事情,那就是除了所有匹配项之外的所有事情……

But I have not figured it out to do the opposite that is everything except all matches ...

推荐答案

好,首先所有人都感谢卡西米尔(Casimir)的帮助。它给了我一个主意:一个主意,即Google的内置功能和强大的regex哈哈。
所以我发现我可以为自己的目的使用自己的自制功能(是的,我不是很最新 ...)。
这就是它了(它的编码不是很好,它的返回值成倍增加。但是,不是正确地修复它,而是在它的上面使用了内置的UNIQUE()函数来摆脱它们,所以是的,它很丑而且我很懒惰,但它确实可以完成工作,即指定正则表达式上所有匹配项的列表(即:1 [0-9] {9}):

Ok guys, first of all thank you Casimir for your help. It gaves me an idea : the idea that it will not be possible with a built-in functions of Google and a strong regex lol. So I found out that I can make my home made function for my own purpose (yes I'm not very "up to date" ...). So here is it (it is not very well coded and its returns doublons. But rather than fixing it properly, I use the built in UNIQUE() function on top of if to get rid of them, so yes it's ugly and i'm lasy but it does the job, that is, a list of all matches of on specifi regex (which is : 1[0-9]{9}) :

function ti_extract(input) {
  var tab_tis = new Array();
  var tab_strings = new Array();


  tab_tis.push(input.match(/1[0-9]{9}/));

  var string_modif = input.replace(tab_tis[0], " ");
  tab_strings.push(string_modif);

  var v = 0;
  var patt = new RegExp(/1[0-9]{9}/);
  var fin = patt.test(tab_strings[v]);

  var first_string = tab_strings[v];


  do {
    first_string = tab_strings[v]; // string 0
    tab_tis.push(first_string.match(/1[0-9]{9}/));

    var string_modif2 = first_string.replace(tab_tis[v], " ");
    tab_strings.push(string_modif2);

    v += 1;
  }
  while(v < 15)

  return tab_tis;
}

这篇关于Google表格:REGEXREPLACE匹配除特定模式以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆