Python.Extract numbers of srings list which are in between brackets and leave a prefix and the number as result

I tried to modify it to extract only the string between brackets only but anything else that do not have breackts appear as empty item in sublists. I would like to get the result below done with OOTB nodes or Designscript

import sys
import re

original_list = IN[0]
OUT = [[re.findall(r"\[([a-zA-Z0-9 ._]*)\]", i) for i in sublst] for sublst in original_list]

@ruben.romero
I suggest you study the python “re” module and regex, you can build the solution that suits you best

import sys
import re

def get_value(txt):
	check = re.search(r'\[(\d+)\]', txt)
	if check is None:
		return txt
	else:
		return check.group(1)

original_list = IN[0]
OUT = [[get_value(i) for i in sublst] for sublst in original_list]
2 Likes