Reputation: 4807
I have a dataframe with the string column as:
df['C23']
Col1 Col2
11 /*[lion]*/
21 /*[tiger]*/
I need the following:
Col1 Col2
11 lion
21 tiger
I tried the following code:
df['C23'].str.extract(r"/*(.*?)*/')
but it produces empty strings.
Upvotes: 1
Views: 899
Reputation: 260640
Assuming you want to convert /*[lion]*/
to lion
and all elements follow the same pattern, you do not need a regex, just slice:
df['Col2'] = df['Col2'].str[3:-3]
Upvotes: 0
Reputation: 626826
You can use
df['result'] = df['C23'].str.extract(r"/\*\[(.*?)]\*/")
The /\*\[(.*?)]\*/
regex matches
/\*\[
- /*[
string(.*?)
- Group 1: any zero or more chars other than line break chars as few as possible]\*/
- ]*/
stringUpvotes: 1