I’m writing a Ruby script to go through a text file and pull the second occurrence of a Regular Expression pattern in each line. Here is an example one line of text:
gi|324021737|ref|NM_001204301.1| gi|324021738|ref|NP_001191230.1| 100.00 459 0 0 1080 2456 294 752 0.0 905
The number I’m trying to get is the one that is gi|324021738 in the above example, but not the gi|324021737 that comes at the beginning of the line. These values always begin with gi|, but the number of digits following them varies.
What would be the most efficient way to append only the second match to the Regex to an array of strings?
You can use this regex: –
And get the group 1 out of it.