1

I have a DF with Credit Card Expiration date in a column (format = mm/yy) I desire to get the Cards that will expire in mm/25 (year = 2025)

I'm trying to use regex to filter the serie but its going wrong

I tested some regex to understand what is being filtered and I got this

df.Exp_Date.filter(regex='.+') --> recognize all dates
df.Exp_Date.filter(regex='.+\/') --> return empty list 
df.Exp_Date.filter(regex='.+\/.+') --> return empty list

df.Exp_Date.filter(regex='\w+') --> recognize all dates (ok)
df.Exp_Date.filter(regex='\w+\/') --> return empty list
df.Exp_Date.filter(regex='\w+\/\w+') --> return empty list

My problem probably is on / char. I tested all regex on regexpal and its working there but not on my filter.

vinicvaz
  • 105
  • 1
  • 11

2 Answers2

1

Try making regex strings raw string like this: regex=r'.+/.+', not regex='.+/.+'

Reason for using raw string is that when you use escape character (backslash), python interprets it differently than regex. Using raw string prevents this.

There is a better explanation here: What exactly is a "raw string regex" and how can you use it?

0

Can you use contains instead:

df1
#Out[472]: 
#   Name   Date    OPP    Result
#0  Will  11/20   @DAL  L110-102
#1  Bill  11/25   @POR  W114-106
#2  Bill  11/24   @LAC    L98-88
#3  Mark  11/25   @LAL  W113-104
#4   Sam  11/25    @NO  W122-104
#5  Dude   9/24  vsSAC  W124-120
#6  What   8/23   @MIL  L115-105

df1[df1.Date.str.contains('/25')]                                                                                                                                                                 
#Out[473]: 
#   Name   Date   OPP    Result
#1  Bill  11/25  @POR  W114-106
#3  Mark  11/25  @LAL  W113-104
#4   Sam  11/25   @NO  W122-104

oppressionslayer
  • 6,942
  • 2
  • 7
  • 24