0

So I am trying to create a program to do the following:

  1. Allow a user to manually input some alphanumeric characters, with some regex included - e.g. ^MASDJOEUFJ0.|^WAOIFUWH2IW9.|^abcd130.
  2. Remove all regex characters/delimiters - ,.|^
  3. Print out the new alphanumeric string - e.g. MASDJOEUFJ0 WAOIFUWH2IW9 abcd130
  4. Load the contents of an Excel spreadsheet into memory, for comparison purposes
  5. Compare the alphanumeric string (in step 3) against the contents of the Excel spreadsheet
  6. Print/highlight only the differences

I am new to Python but using my previous programming experience I have created a program which will do up to step 4 but I am having issues trying to work out the last 2 steps - here is what I've done so far:

import re
import pandas as pd



str = input("Enter Regex : ")

pattern = r"['^\', '\\.|']"

str = re.sub(pattern, " ", str)

#str = str.split()

print (str, "\n", "\n")



df = pd.read_excel (r"C:\Users\...\...\...\Spreadsheet_Comparison.xlsx")

#print (df, "\n", "\n")

I am not sure if I have even used the correct approach so far or not, so any help/guidance here is appreciated.

I am aware that this might not be the most professional way of writing this program but I don't need it to be, I just need something basic that will do the job, and that is easy and straightforward to follow.

Thanks in advance for all the help.

4
  • your regex should look like this f"[\^.|,]", and you need to avoid using the str as a variable name because it is a reserved word (data type) - I don't know the right world Commented Jun 10, 2022 at 16:06
  • I'm not sure what do you mean by highlight the differences, since it seems the user can input anything. So, it's likely that there are going to be always differences. Even if the input were equal to one cell in your spreadsheet, it would be different to the others. An example of how your DataFrame looks like, and specially one your desired output would help a lot. Commented Jun 10, 2022 at 16:27
  • Pleas, take a look at stackoverflow.com/questions/30944577/…, stackoverflow.com/questions/56170164/…, and stackoverflow.com/questions/17972938/…. Commented Jun 10, 2022 at 16:47
  • And also, for the last point, take a look at stackoverflow.com/questions/72522475/…. Commented Jun 10, 2022 at 17:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.