Небольшой трик с регулярными выражениями который редко вижу в чужом коде.
Допустим, вам нужно распарсить простой текст и вытащить оттуда пары имя+телефон. Вернуть всё это надо в виде списка словарей. Возьмем очень простой пример текста.
>>> text = '''
>>> Alex:8999123456
>>> Mike:+799987654
>>> Oleg:+344456789
>>> '''
Соответственно, для выделения нужных элементов будем использовать группы. Получится такой паттерн:
(\w+):([\d+]+)
Как мы будем формировать словарь из найденных групп?
>>> import re
>>> results = []
>>> for match in re.finditer(r"(\w+):([\d+]+)", text):
>>> results.append({
>>> "name": match.group(1),
>>> "phone": match.group(2)
>>> })
>>> print(results)
[{'name': 'Alex', 'phone': '8999123456'}, ...]
Можно немного сократить запись используя zip
>>> results = []
>>> for match in re.finditer(r"(\w+):([\d+]+)", text):
>>> results.append(dict(zip(['name', 'phone'], match.groups())))
Но есть способ лучше! Это именованные группы в regex. Можно в паттерне указать имя группы и результат сразу забрать в виде словаря.
>>> for match in re.finditer(r"(?P<name>\w+):(?P<phone>[\d+]+)", text):
>>> results.append(match.groupdict())
То есть всё что я сделал, это добавил в начале группы (внутри сбокочек) такую запись:
(?P<group-name>...)
Теперь найденная группа имеет имя и можно обратиться к ней как к элементу списка
>>> name = match['name']
Либо забрать сразу весь словарь методом groupdict()
>>> match.groupdict()
#tricks#regex
Lookonchain | ꘜ
A newly created wallet (0xa523) deposited 23.52M $USDC into #Hyperliquid to buy 466,421 $HYPE ($21.5M) and 2.16M $Fartcoin ($2.12M) in the past 7 hours.
https://hypurrscan.io/address/0xa5232e97b4ded3d2EF25Be059c3489e61Be475Aa
A newly created wallet deposited $3.18M $USDC into #HyperLiquid and opened an $ETH long position with 20x leverage.
The whale is likely to increase the position or open a new one.
@Runlifenick_fx✅
A mysterious whale wallet 0x579f has deposited $2.91M USDC into #Hyperliquid over the last 48 hours — taking massive leveraged bets across three major assets:
• Short 232 BTC (~$25M)
• Short 5,810 ETH (~$22.7M)
• Long 44.79M ENA (~$21.3M)
That’s a combined open position of nearly $70M, signaling a strong rotation from majors to ENA.
https://hypurrscan.io/address/0x579f4017263b88945d727a927bf1e3d061fee5ff
A whale recently created a new wallet (0xb0a0) and deposited $4 million USDC into #Hyperliquid, signaling a major move to accumulate $HYPE.
So far, the wallet has purchased 58,778 $HYPE worth approximately $2.89 million.
https://hypurrscan.io/address/0xb0a0f97898682E3c0A83633DF67E67249d6B12fa
As $UNI is trading at ~$10, a whale holding a $UNI long position with 10x leverage currently has a floating profit of $3M on #HyperLiquid.
The whale also has long positions on $ETH (25x), $BTC and $SOL with 20x leverage, with floating profit of $9.38M.
Overall, the whale is making $31.9M.
https://hyperbot.network/trader/0x9263c1bd29aa87a118242f3fbba4517037f8cc7a
A newly created wallet "0x01f" deposited 242 $ETH into #HyperLiquid to sell, then opened a 3,286.46 $ETH short position with 20x leverage valued at ~$7M.
https://hyperdash.com/address/0x01f135c734b4aae018ebf4e7995c560a38422e50
https://x.com/OnchainLens/status/2041019716492537964
Follow @onchainlens for more onchain updates
After 5 months, a whale deposited $1M $USDC into #HyperLiquid and opened a 20,000 $BRENTOIL long position with 20x leverage.
Previously, the whale has made over $12.44M.
https://hyperbot.network/trader/0x9aB1c356E6Af86361446497FCe954B3CDF940206
https://x.com/OnchainLens/status/2040359551682412700
Follow @onchainlens for more onchain updates
A wallet deposited $2.25M $USDC into #HyperLiquid and opened a 2,271.55 $GOLD ($10M) long position with 10x leverage. https://hyperbot.network/trader/0x06a33efba1ea066af486d3d8b89eea896ec1cf69 https://x.com/OnchainLens/status/2036242636579938809 Follow @OnchainLens…
Machi deposited another $300K USDC into #HyperLiquid to increase his $ETH (25x) long position.
Earlier, Machi partially closed the position at a loss to avoid liquidation.
Machi’s loss is now over $31.29M.
https://hyperbot.network/trader/0x020ca66c30bec2c4fe3861a94e4db4a498a35872
https://x.com/OnchainLens/status/2039617823027425483
Follow @onchainlens for more onchain updates
A newly created wallet deposited $9.6M $USDC into #HyperLiquid and opened a $CL long position with 20x leverage. The position is still increasing. https://hyperbot.network/trader/0x9D32884370875f2960D5CC4b95Be26687d69Aff5 https://x.com/OnchainLens/statu…