I have a pyspark Dataframe, I would like to improve the regex bellow. I want to add a condition or modify the regex to:
- recover all number that is attached to a
/
orletter
in the end.
Example of case1:
column_example | new_column
------------------------------------------------------|----------------- |
mundo por el número de NJU/LOK 12345T98789-hablantes | 12345
hispanohablantes ZES/UJ86758/L87586:residentes en | 86758
Example case 2:
- I shouldn't take the number that arrived after ABC word.
Column Example:
My_column | new_column
------------------------------------------------------|---------------------
mundo por el número de ABC 8567 hablantes | []
------------------------------------------------------|---------------------
con dominio nativo ABC 987480 millones de personas | []
------------------------------------------------------|---------------------
hispanohablantes residentes en ABC98754 otros países | []
The following code is:
ptn = re.complie(r'^(?:MOD)?[0-9]{4,6}$')
array_filter = udf(lambda arr: [ x.lstrip('MOD') for x in arr if re.match(ptn, x) ] if type(arr) is list else arr, ArrayType(StringType()))
How can I do it ? Thank you