Remove Leading Dollar Sign From Data And Improve Current Solution
I have string like so:
"Job 1233:name_uuid (table n_Cars_1234567$20220316) done. Records: 24, with errors: 0."
I'd like to retieve the datte from the table name, so far I use:
but this yields $20220316. How do I get only the date, without $?
I'd also like to get the table name: n_Cars_1234567$20220316
So far I have this:
pattern_table_info = "\(([^\)]+)\)" pattern_table_name = "(?<=table ).*" table_info = re.search(pattern_table_info, message).group(1) table = re.search(pattern_table_name, table_info).group(0)
However I'd like to have a more simpler solution, how can I improve this?
You can write a single pattern with 2 capture groups:
The pattern matches:
(Capture group 1
\w+\$match 1+ word characters and
(\d+)Capture group 2, match 1+ digits
)Close group 1
import re s = "Job 1233:name_uuid (table n_Cars_1234567$20220316) done. Records: 24, with errors: 0." m = re.search(r"\(table (\w+\$(\d+))\)", s) if m: print(m.group(1)) print(m.group(2))
- → How to configure JSON for graphql query?
- → Google couldn't fetch my sitemap.xml file
- → A lot of socket endpoints in python?
- → Historical price per minute between two timestamps for a cryptocurrency
- → How to get a value from a list of dictionaries - Python 3.7.1
- → What is the optimal way to parse these strings in Python?
- → Short Order on Binance futures testnet resulting in APIError (ReduceOnly Order is Rejected)
- → values subtracted while iterating through list has random miscalculations
- → Foreign key query error in case of custom uint64 field which was used as a primary key
- → Grouping all tests Python
- → Using #!python2 not working to run under Python 2
- → Storing last 3 scores and deleting older scores and calculating average?
- → Checking if input is in a list of numbers in python