I have a bunch of strings in a text file that have values in them I want to capture into groups. Each line/row in the text file is a unique record, but the values usually stick to a prescribed format in each line:
ValueA ValueD ValueS ValueR ValueW ValueT
ValueX ValueW ValueB ValueM ValueQ ValueA
Etc. If I want to capture ValueA into capture group 1 and ValueW into capture group 2, can I do so using a single regex that handles things properly irrespective of the position in each line of text of the values in question?
The goal is to then use the capture groups to write back out to a file the two captured values so that I can order them, i.e., “ValueW ValueA”.
You could use something like:
Perl example:
Output:
Also at http://ideone.com/IhGfS
Note: If you are just matching you won’t need that last
.*, and depending on how well matching the ValueX patterns are you could remove all the?.