I want to do the above with the UTF-8 character code.
If i just normally want to count all double-byte spaces,
str = '2019/11/2 today's date' pritnt str.count ('\ u3000')
From "2019/11/2 today's date"
This is the number of full-width blank strings before 2019/11/2
I want to return.
Can you tell me if there is any good way to do it?
Answer # 1
>>>import re >>>s = '2019/11/2 today's date' >>>re.match (r "\ u3000 *", s) .end () 3
re.matchis conveniently used to match only at the beginning of the string.
re --- Regular expression manipulation — Python 3.8.0 documentation
raw-strings is used,
\ u3000is recognized as a double-byte space by the regular expression parser, and since
*is used, it must match (If the first character is not a full-width space, a match object of
span = (0, 0)will be returned) is added as a reminder.
Answer # 2
An easy-to-understand method is to use a single character slice and look at the first character in order, and count until it is not a full-width space character or the string is exhausted. is.
Answer # 3
This is the way I came up with.
src = '2019/11/2 today's date' print ( len (src)-len (src.lstrip ('')) )
Answer # 4
It's a bit verbose in terms of processing, but ...
>>>import re >>>str = '2019/11/2 today's date' >>>print (len (re.split ('[^ \ u3000]', str) )) 3
Answer # 5
>>>import re >>>str = '2019/11/2 today's date' >>>re.search (r '[^ \ u3000]', str) .start () 3
- python 3x - how to count the number of data extracted by pandas or how to solve the error
- python - how to count the number of characters in a character string including a regular expression
- python - i want to convert the count type picked up by counter to a number type
- extract title and video count with python youtube api
- python - count by element with pivot_table in pandas
- python - how to count url clicks in django and record them in the db
- how to count days of the week python
- how to write to count the number of specific elements of dictionary values in python3