REGEX IN DATAFRAME PANDAS

Viewed 35

I have a dataframe with a column like that

COL1
PACK[5.95 $ /if game game1 + game1]
PACK[3 $ /2 products.]

I want create other column as following according COL1

pack_plus    pack
5,95          3          

I am ok for pack_plus : PACK\[(\d[\d.]*) $[^][]*\+[^][]*]

but not for pack (I dont want to select raw with "+")

I have this : PACK\[(\d[\d.]*) €[^][()]*]

Thank you

1 Answers

You can use

PACK\[(\d[\d.]*)\s*\$[^][+]*]

See the regex demo.

Details

  • PACK\[ - PACK[ string
  • (\d[\d.]*) - Group 1: a digit and then zero or more digits or dots
  • \s* - zero or more whitespaces
  • \$ - a $ char
  • [^][+]* - zero or more chars other than ], [ and +
  • ] - a ] char.
Related