string is split into two parts in front of parentheses and in parentheses?
for example,
ABC1.1 (1) is split into ABC1.1 and 1
% DEF2.1 (3) is split into% DEF2.1 and 3
@ I GHI3.3 O GHI3.3 (5) is split into @ I GHI3.3 O GHI3.3 and 5
string is split into two parts in front of parentheses and in parentheses?
for example,
ABC1.1 (1) is split into ABC1.1 and 1
% DEF2.1 (3) is split into% DEF2.1 and 3
@ I GHI3.3 O GHI3.3 (5) is split into @ I GHI3.3 O GHI3.3 and 5
import re
matchObj = re.match(r'(.+)\((\d)\)','ABC1.1(1)')
if matchObj:
print("matchObj.group() : ", matchObj.group())
print("matchObj.group(1) : ", matchObj.group(1))
print("matchObj.group(2) : ", matchObj.group(2))
segment_test = re.compile(r'(.*)\((.*)\)')
match = segment_test.match('%DEF2.1(3)')
print match.group()
print match.group(1)
print match.group(2)
regularization is as follows [I can't py, but can only give regularization]:
([^()]+)\(([^()]*)\)
or directly, replace it with empty
>>>import re
>>>pattern = re.compile(r"(.*?)\((.*?)\)", flags=re.DOTALL)
>>>pattern.findall("@ I/O GHI3.3(5)")
[('@ I/O GHI3.3', '5')]
>>>pattern.findall("ABC1.1(1)")
[('ABC1.1', '1')]
>>>pattern.findall("%DEF2.1(3) ABC1.1(1) @ I/O GHI3.3(5) ")
[('%DEF2.1', '3'), (' ABC1.1', '1'), (' @ I/O GHI3.3', '5')]
import re
s1 = 'ABC1.1(1)'
s2 = '%DEF2.1(3)'
s3 = '@ I/O GHI3.3(5) '
r1 = re.split('\(|\)', s1)
print(r1[0] , r1[1])
r2 = re.split('\(|\)', s2)
print(r2[0] , r2[1])
r3 = re.split('\(|\)', s3)
print(r3[0] , r3[1])
Previous: Failed to get Ali nail TOKEN
Next: Some errors about timeout and connection when scrapy uses proxy ip to grab data
use reg = (? < = mileage). (re.findall: km | km (?! ) | (em: km | km (?! ). (? = mileage) the method is re.findall the text above is input the list below is output for example, for the first one, I only need to take 34km , for example, fo...
The expression in the question is a little unclear: specifically, the reason is a malfunction of the CPU circuit board and needs to be replaced. B= CPU circuit board import re C = re.search (A Magi B) print (C) how to get the index value of CPU c...
assume that all entity names are stored in the A.xlxs (to add, hundreds of entities, tens of thousands of sequences), and assume that one of the sequences reads: "there are bad spots on the screen visible on the scene, the sound of the handset is too ...
< span data-original-name= < Duke University Blue Devil Men s Basketball team > Duke University Blue Devil Men s Basketball team < span data-original-name= "unknown " > unknown how to get the Duke University Blue Devil Men s Basketball team out...
for example: the newly released Samsung Galaxy S9 features as follows: 1. The Exynos9810 processor is adopted, and the 2.RAM is 4GB. The battery capacity is 3000mAh. expect to extract the S9 Magi Exynos 9810 GB mAh. I hope you can give me some advice o...
ret=re.search (r dudes) print (ret.group ()) results do not meet expectations: 999 ...
str = "http: bbs.aa.cc avatar.php?uid=157135&size=large " " I want to match uid=157135, and the position where this parameter appears is not necessarily fixed. for example, put at the end: http: bbs.aa.cc avatar.php?s. or first ...
refers to a problem in offer, please implement a function to determine whether a string represents a numeric value (including integers and decimals). For example, the strings "+ 100 ", " 5e2 ", "-123 ", "3.1416 " and "- 1E-16 " all represent numeric...
how do you use Python to match the two parameter values in SetValue in the following string? for example, several pieces of data failed to match between "Att_Sys_zh-cn_11_G " and 12 12 5 . <script> function init(){ SetValue( txt_gtin , &...
python regular matches the contents of the specified start HTML tag and end tag <div class="pbm mbm bbda cl"> <h2 class="mbn">< h2> <a href="http: bbs.aa.cc home.php?mod=spacecp&ac=p...
The problem is as follows, as seen in the python getting started manual, re.sub () replaces I know the syntax of re.sub (regular string, replacement string, original string), but I don t understand this I also know that 1 is equivalent to re.sea...
not long after I first came into contact with python, I needed to use regularities when crawling pages, but I was confused after reading python s re library for a long time. Maybe I got silly after a whole day s work. =-sharp I have many of the follow...
I now have a string 5900A7395900A7545900A414 . I want to divide this string into three separate strings 5900A739 , 5900A754 , and 5900A414 how can I use capture groups to implement the above requirements? Note that this is just an example, the actua...
response = requests.get( https: 36kr.com newsflashes ) all_list=re.findall( "title":"(.*?)","catch_title":"","description":".*?","cover":"","new...
sss= "http: www.qhnews.com newscenter system 2014 07 22 011460349.shtml I want the number after the last " "...
has a string like this 000001 000002 I want to divide it into the form of stock symbol + company name by regular this is my regular re.split(" s+", string) but the segmented result is 000001 , 000002 , , ...
topic description The requirement is to replace the better in text with that strong in the regular mode of the sub method, where I have added r to indicate escape. Why add a , written as r * (. *?) *? Why can t you just write ringing * (....