Reputation: 31
I have a string like this:
TransID [12345, 67890]; Btool_ID [22222]; Reconsile [ccccc]; RequestID [ aaaaa];
I want to extract the string in TransID[], but when I use the code:
gsub(".*TransID \\[(.*)\\].*", "\\1", data)
It gave me:
12345, 67890]; Btool_ID [22222]; Reconsile [ccccc]; RequestID [ aaaaa
My desired output is:
"12345, 67890"
How could I do that? Thank you
Upvotes: 0
Views: 49
Reputation: 51592
How about,
sub('TransID \\[(\\d+, \\d+)\\].*', '\\1', x)
#[1] "12345, 67890"
Upvotes: 1