If you have strings like this, I want to get only strings with date patterns.
Is it possible to filter out only certain strings by pattern?
of # example data.
a = [
'Vaasa Lama the Korean alphabet'
On Feb. 2 is the ' 2020.'
, '145692'
, 'This is a few years ago and on February 2, by 2020.'.
]
# desired results.
a = [
' On Feb. 2 is 2020.'
, 'This is a few years ago and on February 2, by 2020.'.
]
python
It is possible with regular expression. Regular expressions are difficult, but it is useful to study a little.
# Data Example
a = [
'Vaasa Lama the Korean alphabet'
On Feb. 2 is the ' 2020.'
, '145692'
, 'This is a few years ago and on February 2, by 2020.'.
]
# desired results.
a_ = [
' On Feb. 2 is 2020.'
, 'This is a few years ago and on February 2, by 2020.'.
]
import re
for s in a:
res = re.search(r"\d{4} \d{1,2}month \d{1,2}day", s)
if res:
print(s)
a_filtered = [s for s in a re.search(r"\d{4} \d{1,2}month \d{1,2}day,s)]
print(a_filtered)
1235 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
856 Uncaught (inpromise) Error on Electron: An object could not be cloned
758 Error in x, y, and format string must not be None
771 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2025 OneMinuteCode. All rights reserved.