简体   繁体   English

我只需要打印一次,因为我在python中使用正则表达式将它打印了两次

[英]i need to print only once as i am getting it printed twice using regex in python

importre
list = re.findall('SF:((/\w*)*.c$)','SF:/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c')
print(list)

output: 输出:

[('/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c', '/https_util')]

but i need only: 但我只需要:

/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c

In that case instead of using findall you can use search and get the respective group as shown below 在这种情况下,您可以使用search并获取相应的组,而不是使用findall,如下所示

import re
list = re.search('SF:((/\w*)*.c$)','SF:/x/eng/rlse/DOT/devN_170820_0500/zephyr/src/libzapid/https_util.c')
print(list.group(1))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在使用递归函数,并且只需要在函数中打印一次 - I am using a recursive function and need to print from within the function just once 获取一个打印语句两次打印一个值的不同输出,python - Getting a print statement printed twice with different outputs for one value, python 我想一次添加一个值,但是要添加两次,如果我先打印该值,它只会被添加一次 - I want to add a value once but gets added twice and if i print the value first it only gets add once 为什么我必须在 python 中添加三次打印 function 我只需要打印一次即可获得 output - Why do I have to add print function thrice in python i need to give print only once to get the output 使用python的请求模块打印GET respose的内容时,为什么会得到空输出? - Why am I getting an empty output when I print the content of GET respose using requests module of python? 我正在尝试使用 for 循环打印转义字符。 我的动机是查看打印出来的值 - I am trying to print escape characters using for loop. My motive is to see the values that gets printed 我想在python中的while循环中只打印一次 - I want to print something only once in a while loop in python 打印我重复打印两次,有什么方法只打印一次 - Print i prints repeated number twice, is there any method for printing it only once 数据被抓取和打印只是每页的第一个条目,但我需要所有数据 - Data getting scraped and printed is only the first entry of each page but I need all the data 如何在 Python 中只替换一次正则表达式? - How can I substitute a regex only once in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM