Reputation: 1262
I have a 2 column tsv file with column one having
1-FN3Z1-206329557431
1-FN411-153115736976
Where I am trying to remove the first two parts of the value (i.e to extract 206329557431
and 153115736976
). I've used online regex tool to generate the patterns
pattern
".*?\\d+.*?\\d+.*?(\\d+)"
AND ".*?\\d+.*?\\d+.*?\\d+.*?(\\d+)"
Independently they work fine. I'm trying to look for a combined regex pattern. Any pointers as to how this can be done.
Upvotes: 1
Views: 81
Reputation: 313
How about this regexp : .-.{5}-
looks like it can matches all statements but it depends on your format.
Here is Java code example :
@Test
public void test() {
String test = "1-FN3Z1-206329557431 1-FN411-153115736976";
String result = test.replaceAll(".-.{5}-", "");
assertEquals("206329557431 153115736976", result);
}
Upvotes: 1
Reputation: 60046
Why don't use split
for example :
String spl = "1-FN411-153115736976".split("-")[2];
If you want a regex you can use (.*?-){2}(.*)
, which mean get everything after the second -
Output
206329557431
153115736976
Upvotes: 4
Reputation: 522817
If the strings in your TSV file all have the same widths and patterns, then you can just use substring here:
String tsv = "1-FN3Z1-206329557431";
System.out.println(tsv.substring(8));
Upvotes: 1