I want to match the sentences that have been broken in Excel cells with regular expressions.

Asked 1 years ago, Updated 1 years ago, 105 views

I'm sorry to ask you about May rain.
We are trying to create a program that determines whether each cell in Excel has a . at the end or not.

If the sentence is not a new line in the cell, we were able to judge it by the following code.
However, if the same sentence had a new line, we could not judge by the same code.

Code

import openpyxl
import re

wb=openpyxl.load_workbook(r"sample.xlsx")

ws = wb.active
source=ws["A8"].value


pattern=r"(1.*?)(.)(2.*?)(.)"

if re.search(pattern, source):
    print("Out")

#--- Single line description in A8 cell (no line breaks) ----
A8
①Test. て Test.

Run Results
It came out

#--- Two lines in A8 cell with line breaks ----
A8
①Test.
②Test.
Run Results
No Output

Is it possible to create a code that determines whether a new line is attached to the end of a sentence in a cell?
I think this is a basic question, but I appreciate your cooperation.

python regular-expression openpyxl

2022-09-30 16:17

1 Answers

I could have done it with the following description.Sorry for the trouble.

pattern=r"(1.*?)(.)(|\n)(2.*?)(.)"


2022-09-30 16:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.