Python Forum
regular expressions in openpyxl. format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regular expressions in openpyxl. format
#1
In excell i have a column which contains several words. For my program I need only first one (and only letters). For example, cell -'dog,dogge', but we need only 'dog'.
I made the programm but the form of output is very strange. Need your help what to change.

My code:
import openpyxl
import re
source_file=openpyxl.load_workbook((r’C:\Users\user\Desktop\Питон\Слова_английский.xlsx’))
first_sheet = source_file.worksheets[0] #активный первый лист
column_b = first_sheet[‘B’] #столбец B

for i in range(len(column_b)):
keyRegex = re.compile(r'([а-яА-Я ]+)’)
column_b_correct = keyRegex.search(str(column_b[i].value))
print(column_b_correct)
I have the result:
Output:
<re.Match object; span=(0, 7), match=’реклама’> <re.Match object; span=(0, 6), match=’комикс’> <re.Match object; span=(0, 6), match=’беседа’>
But I need only the words itself:
Output:
реклама комикс беседа
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Recursive regular expressions in Python risu252 2 1,205 Jul-25-2023, 12:59 PM
Last Post: risu252
Sad Regular Expressions - so close yet so far bigpapa 5 948 May-03-2023, 08:18 AM
Last Post: bowlofred
  Having trouble with regular expressions mikla 3 2,578 Mar-16-2021, 03:44 PM
Last Post: bowlofred
  Statements and Expressions Julie 1 1,627 Feb-26-2021, 05:19 PM
Last Post: nilamo
  Convert date integers (ex. 43831) to regular format Galven 2 2,604 Nov-15-2020, 11:38 PM
Last Post: bowlofred
  Regular Expressions pprod 4 3,066 Nov-13-2020, 07:45 AM
Last Post: pprod
  Format phonenumbers - regular expressions Viking 2 1,890 May-11-2020, 07:27 PM
Last Post: Viking
  Unexpected (?) result with regular expressions guraknugen 2 2,205 Jan-18-2020, 02:33 PM
Last Post: guraknugen
  openpyxl, if value in cell then change format genderbee 1 5,237 Nov-05-2019, 01:37 PM
Last Post: genderbee
  Strange output with regular expressions newbieAuggie2019 1 1,925 Nov-04-2019, 07:06 PM
Last Post: newbieAuggie2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020