删除字符后的所有单词/包括它

时间:2019-06-03 18:39:20

标签: r

我有这个用名称行调用的元素列表

 row <-

    [[798]]
    [1] "SINE/tRNA-Deu"

    [[799]]
    [1] "Simple/repeat"

    [[800]]
    [1] "SINE/tRNA-Deu"


    [[802]]
    [1] "SINE/tRNA-gip"

    [[803]]
    [1] "Simple/repeat"

    [[804]]
    [1] "SINE/MIR"

    [[805]]
    [1] "SINE/tRNA-Deu"

    [[806]]
    [1] "Simple/repeat"

    [[807]]
    [1] "SINE/tRNA-Deu"

    [[808]]
    [1] "SINE/tRNA-Deu"

    [[809]]
    [1] "SINE/tRNA-Deu"

    [[813]]
    [1] "Low_complexity/alfa"

有没有一种方法可以消除所有元素中/之后的所有单词? 我已经尝试过:

row1 <- gsub("(/).*", "\\1", row)

,但在输出中不删除字符“ /”。我不想将其包含在元素名称中(例如SINE,Simple等):

[1] "SINE/" "Simple/" "SINE/" "SINE/" "Simple/"

[6] "SINE/" "SINE/" "Simple/" "SINE/" "SINE/"

[11] "SINE/" "Low_complexity/"

我的代码中的错误在哪里?

1 个答案:

答案 0 :(得分:2)

一个简单的解决方法,不要使用捕获组:

<Image Source="state_default.png" Margin="10,0,0,0">
    <Image.Triggers>
        <DataTrigger TargetType="Image" Binding="{Binding State}" Value="Assigned">
            <Setter Property="Source" Value="state_assigned.png" />
        </DataTrigger>
    </Image.Triggers>
</Image>