Sponsored Content
Full Discussion: Python re.search vs re.sub
Top Forums Programming Python re.search vs re.sub Post 302965355 by metallica1973 on Wednesday 27th of January 2016 05:58:34 PM
Old 01-27-2016
Python re.search vs re.sub

I am having trouble understanding why these two commands differ with one producing the desire results and the other not. An example:
Code:
capture_str = 'xserver-xorg-video-qxl-dbg (0.1.1-2+b2 [s390x], 0.1.1-2+b1 [amd64, armel, armhf, i386, mips, mipsel, powerpc], 0.1.1-2 [arm64, ppc64el]) X.Org X server -- QXL display driver (debugging symbols)'

re.search(r'(?<=\[s390x\]\, ).*', capture_str).group(0)
'0.1.1-2+b1 [amd64, armel, armhf, i386, mips, mipsel, powerpc], 0.1.1-2 [arm64, ppc64el]) X.Org X server -- QXL display driver (debugging symbols)'

re.sub(r'(?<=\[s390x\]\, ).*', '', capture_str)
'xserver-xorg-video-qxl-dbg (0.1.1-2+b2 [s390x], '

I am truly confused at why "re.sub" doesnt perform a positive lookbehind that re.search can do. It appears to be doing the opposite with the same regex. What is the difference?

Last edited by metallica1973; 01-27-2016 at 07:11 PM..
 

8 More Discussions You Might Find Interesting

1. SuSE

"ssh suse-server 'python -V' > python-version.out" not redirecting

Okay, so I have had this problem on openSUSE, and Debian systems now and I am hoping for a little help. I think it has something to do with Python but I couldn't find a proper Python area here. I am trying to redirect the output of "ssh suse-server 'python -V'" to a file. It seems that no matter... (3 Replies)
Discussion started by: Druonysus
3 Replies

2. Programming

Search for a File Python

I am back at it with Python and have run into a little stupid hurdle. My goal is to simply search for the GeoIP.dat database and add the path to a couple of variables. So for example: geopath=os.system('find /usr/share -iname GeoIP.dat') geobase = pygeoip.GeoIP(geopath, pygeoip.MEMORY_CACHE)... (3 Replies)
Discussion started by: metallica1973
3 Replies

3. Shell Programming and Scripting

[Python] Search a file with paramiko

I need to compare the output files in a directory for sftp, looking through a mask. Return the full file name. Eg. I have a file named locally: test.txt I must check through sftp, if a file with the following name: test_F060514_H173148.TXT My idea is for the filename to a... (0 Replies)
Discussion started by: Jomeaide
0 Replies

4. Shell Programming and Scripting

**python** unable to read the background color in python

I am working on requirement on spreadsheet in python scripting. I have a spreadsheet containing cell values and with background color. I am able to read the value value but unable to get the background color of that particular cell. Actually my requirement is to read the cell value along... (1 Reply)
Discussion started by: giridhar276
1 Replies

5. Shell Programming and Scripting

Search and Replace+append a text in python

Hello all, I have a verilog file as following (part of it): old.v: bw_r_rf16x32 AUTO_TEMPLATE ( 1957 // .rst_tri_en (mem_write_disable), 1958 .rclk (clk), 1959 .bit_wen (dva_bit_wr_en_e), 1960 .din ... (5 Replies)
Discussion started by: Zam_1234
5 Replies

6. Windows & DOS: Issues & Discussions

How to execute python script on remote with python way..?

Hi all, I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine.. Below is the code I am trying: #!/usr/bin/env python import wmi c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")... (1 Reply)
Discussion started by: onenessboy
1 Replies

7. Programming

Search or find a element inside list python

I have a list as follows: From this i need to grep the element using keyword as "primary" and return output as 12:13-internet-wifi-primary i used as follows if (i <= (len(system_info))): ss = system_info print... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies

8. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
GRUB-MKIMAGE(1) 						   User Commands						   GRUB-MKIMAGE(1)

NAME
grub-mkimage - make a bootable image of GRUB SYNOPSIS
grub-mkimage [OPTION...] [OPTION]... [MODULES] DESCRIPTION
Make a bootable image of GRUB. -c, --config=FILE embed FILE as an early config -C, --compression=(xz|none|auto) choose the compression to use for core image -d, --directory=DIR use images and modules under DIR [default=/usr/lib/grub/<platform>] -k, --pubkey=FILE embed FILE as public key for signature checking -m, --memdisk=FILE embed FILE as a memdisk image Implies `-p (memdisk)/boot/grub' and overrides any prefix supplied previously, but the prefix itself can be overridden by later options -n, --note add NOTE segment for CHRP IEEE1275 -o, --output=FILE output a generated image to FILE [default=stdout] -O, --format=FORMAT generate an image in FORMAT available formats: i386-coreboot, i386-multiboot, i386-pc, i386-pc-pxe, i386-pc-eltorito, i386-efi, i386-ieee1275, i386-qemu, x86_64-efi, i386-xen, x86_64-xen, mipsel-yeeloong-flash, mipsel-fuloong2f-flash, mipsel-loongson-elf, pow- erpc-ieee1275, sparc64-ieee1275-raw, sparc64-ieee1275-cdcore, sparc64-ieee1275-aout, ia64-efi, mips-arc, mipsel-arc, mipsel-qemu_mips-elf, mips-qemu_mips-flash, mipsel-qemu_mips-flash, mips-qemu_mips-elf, arm-uboot, arm-efi, arm64-efi -p, --prefix=DIR set prefix directory -v, --verbose print verbose messages. -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options. REPORTING BUGS
Report bugs to <bug-grub@gnu.org>. SEE ALSO
grub-install(8), grub-mkrescue(1), grub-mknetdir(8) The full documentation for grub-mkimage is maintained as a Texinfo manual. If the info and grub-mkimage programs are properly installed at your site, the command info grub-mkimage should give you access to the complete manual. grub-mkimage (GRUB) 2.02-2ubuntu8.3 July 2018 GRUB-MKIMAGE(1)
All times are GMT -4. The time now is 06:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy