Похожие чаты

I have a doubt in Python: how i can assign

the value of an expression of the method re.search() to a variable? I tried:

var = re.search(r'^\d*(?:\s)', string)
print(var)

And it returns:

961230712
None


I need only the numbers to pass them to another program as an argument.
If i remove the print function and the variable assignment:

re.search(r'^\d*(?:\s)', string)

It returns me what (i think) it should:

961230712

The problem is that I can't work with this, since it wasn't assigned to any variable that could be manipulated. So there is no way i can pass the numbers to another program.
Thanks in advance!

4 ответов

10 просмотров

Please format the code you posted, by wrapping it in triple backticks. -> `

Why not re.find()?

Right now my connection is so fucked up, Provide a sample of your string variable

Maybe try an if else condition just in case you don't get a match. Say if re.search(r'regex_exp', string): var = re.search(r'regex_exp', string).group() else: do something else

Похожие вопросы

Обсуждают сегодня

А чем вам питонисты не угодили?😂
.
79
or any website to buy prepaid card with xmr that's not trocador that's down?
Umbrella Party Partner
18
Всем привет, написал код ниже, но он выдает сегфолт, в чем причина? #include <stdio.h> #include <stdlib.h> #include <string.h> struct product { char *name; float price; };...
buzz базз
75
Hi, I can't understand promises in JavaScript and what we should use them for (maybe the teacher didn't teach well XD). Do you have a solution for this? And are promises used...
A
29
Ещё такой вопрос. Мне необходимо хранить пароль пользователя локально. Для этого планирую использовать ini файл. Это для автозаполнения полей логин и пароль при авторизации. Е...
Евгений
19
всем доброго времени суток! имею вопрос: как понять ТОЧНО, что на нексус производится атака или он перегружен? исходные данные: - Nexus OSS 3.67.1-01 на OrientDB - Total co...
Michael Kostelcev
3
Ты просто гитлеровскую эстетику плохо понимаешь. Он же всё под Цезаря делал. А это как бы запрещённый приём в политике. Пиджаки они зачем все носят? Чтобы показать что они тип...
Ivan Kropotkin
4
Xem delist ho rha hai agr naa bhechu toh kya hoga after 1 july?
ABHI
27
i need usdt exchanged to xmr without kyc any site there ?
Certained
12
Did you guys see the latest tweet from TonGifts? 🚀
Mike
44
Карта сайта