Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string parsing with re.search()
#6
delahug Wrote:I then run into the problem above when using re.search() on the square bracket. It's caused (apparently) by the fraction in the first span.
If you are running python 2.7, the problem is not caused by the fraction, it is caused by the implicit attempt to encode the string to the ascii encoding with the str() function, while the fraction character cannot be encoded with this encoding because it is not an ascii character. In python 3, there would be no such problem because str() doesnt try to encode the unicode string.
>>> # python 2.7
>>> text = u"\xbd"
>>> str(text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in position 0: ordinal not in range(128)
You could perhaps try a unicode regex like u"[[]" and remove the call to str(), or better switch to python 3 because python 2 is no longer supported.
Reply


Messages In This Thread
string parsing with re.search() - by delahug - Jun-03-2020, 08:24 AM
RE: string parsing with re.search() - by snippsat - Jun-03-2020, 01:35 PM
RE: string parsing with re.search() - by delahug - Jun-03-2020, 09:23 PM
RE: string parsing with re.search() - by snippsat - Jun-03-2020, 10:20 PM
RE: string parsing with re.search() - by Gribouillis - Jun-04-2020, 03:09 AM
RE: string parsing with re.search() - by delahug - Jun-04-2020, 09:39 AM
RE: string parsing with re.search() - by snippsat - Jun-04-2020, 10:34 AM
RE: string parsing with re.search() - by delahug - Jun-04-2020, 07:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Learning:bs4, re.search] - RegEx string cutoff jarmerfohn 5 3,761 Nov-23-2019, 09:32 AM
Last Post: buran
  Regex search for string DBS 3 4,624 Feb-06-2017, 11:39 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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