-2

I have the following strings in cells in Google Sheet (excluding the double quotes).

"Remote Copy Group 156(nw-prd-db) Degraded (Periodic Sync Took More Than Sync Period {0x7})" "Remote Copy Group 178(fr-prd-db) Degraded (Periodic Sync Took More Than Sync Period {0x7})"

I wish to extract only "nw-prd-db" or "fr-prd-db" from the strings. How can it be done? Thanks.

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
Kim
  • 101
  • 2

2 Answers2

2

Assuming that you have one of these in each cell (for example, in A1), you can use the following regular expression with REGEXEXTRACT:

=REGEXEXTRACT(A1,"\((.+?)\)")

enter image description here

  • This matches one to unlimited characters inside a ( ) (for which escape character is used \(, \). And ? makes the pattern "non-greedy", so it will look for the shortest possible match (so it won't extract the rest of the string, until the second ) at the end).

Or, alternatively:

=REGEXEXTRACT(A1,"\(([^\)]+)\)")
Iamblichus
  • 16,112
  • 2
  • 9
  • 25
0

try:

=ARRAYFORMULA(TRANSPOSE(QUERY(IFNA(REGEXEXTRACT(FLATTEN(
 SPLIT(REGEXREPLACE(A1, "\d+\(", "♦♣"), "♦")), "♣(.+?)\)")), 
 "where Col1 is not null")))

enter image description here

player0
  • 99,092
  • 8
  • 51
  • 98