如何过滤字符串数据?

时间:2019-03-01 19:50:12

标签: javascript arrays string servicenow

我有一个字符串,例如:-

dat = aggregate(list(value = 1:NROW(df)), df[c("age_group", "Gender")], length)
dat$proportion = ave(dat$value, dat$age_group, FUN = function(x) x/sum(x))
ggplot(dat, aes(x = age_group, y = proportion, fill = Gender)) +
    geom_col() +
    coord_flip()

因此,基本上,我使用String: Notification 'Arcosa-Incident assigned to my group' 8ff7afc6db05eb80bfc706e2ca96191f included recipients as manager of a group in the notification's "Groups" field: 'Ruchika Jain' 9efa38ba0ff1310031a1e388b1050e3f 方法将其转换为数组,以逗号分隔值,现在我想.split(' ')此数组,并且只需要32个字符长的值并删除其余值

请帮助我实现这一目标。也欢迎其他解决方案。预先感谢。

2 个答案:

答案 0 :(得分:0)

假设您想获取这些ID,您只需在字符串上使用带有match的正则表达式即可,而无需拆分/过滤。 (注意:我必须对文本中的单引号进行转义。)

const str = 'String: Notification \'Arcosa-Incident assigned to my group\' 8ff7afc6db05eb80bfc706e2ca96191f included recipients as manager of a group in the notification\'s "Groups" field: \'Ruchika Jain\' 9efa38ba0ff1310031a1e388b1050e3f';

const matches = str.match(/[a-f0-9]{32}/g);
console.log(matches);

答案 1 :(得分:-1)

像这样:

var arr = ...;
var filtered = arr.filter(word => word.length === 32);

编辑:如果只想解析GUID,这可能是个坏主意。当然,像“ Ruchika”这样的名称也可以包含32个字符。也许,考虑改用正则表达式。