Regex (sed) that may need to capture multiple expressions per line

awk, regex, sed

Solution

Does

sed 's/\([[:space:]]\|;\)[[:alnum:]]*;/\1/g; s/Name=//g'

work for you?

Problem

I am trying to write a regex that will capture the a name in a file, where some lines may have 2 or more names that need to be captured. For example, I would like to take a file with: ``` Field_1 \t Field_2 \t Field_3 \t JGN;Name=hsa-123;J4N9;Name=cfa-241-b Field_1 \t Field_2 \t Field_3 \t JPN;Name=hsa-1323;JJ39;Name=cfa-255-b;Name=hsa-188 ``` And have an output file return: ``` Field_1 \t Field_2 \t Field_3 \t hsa-123; cfa-241-b Field_1 \t Field_2 \t Field_3 \t hsa-1323;cfa-255-b;hsa-188 ``` I am using the regex as follows: ``` sed 's/\(.*\)\t\(.*\)\t\(.*\)\t.*\;Name=\(.*\);.*/\1\t\2\t\3\t\4\;\4/g' ``` But this only returns the first name. Any suggestions would be greatly appreciated

Original source