Problem description:
Received the following string:
source='s186. ChapterId=1211864040; S186. ContentId=1215033291; S186. ContentType=1; S186. DurationInSeconds=927; S186. FreePreview=null; S186. GmtCreate=null; S186. GmtModified=null; S186. Id=1217999465; S186. JsonContent=null; S186. LearnCount=null; S186. LessonId=1214394275; S186. Live=null; S186. LiveInfoDto=null; S186. Name="5.3.3 rotor critical speed"; ' Use regular expressions:
The pattern=re.com running (r '. *? ContentType=1. *? Id=(\ d +). + name="(. *?) ". *? The test ') Lesson_set=re. The.findall (pattern, source) The results obtained are:
[(' 1214394275 ', '- 5.3.3 rotor critical speed (15:27)')]
Question: I need id is 1217999465, and the expression for the lessonId id value 1214394275
This string of
s186. Id=1217999465 ; S186. JsonContent=null; S186. LearnCount=null;
s186. LessonId=1214394275 Could you tell me how to modify the matching rule should get s186. Id=1217999465 the id value,
CodePudding user response:
The import re Source="' s186. ChapterId=1211864040; S186. ContentId=1215033291; S186. ContentType=1; S186. DurationInSeconds=927; S186. FreePreview=null; S186. GmtCreate=null; S186. GmtModified=null; S186. Id=1217999465; S186. JsonContent=null; S186. LearnCount=null; S186. LessonId=1214394275; S186. Live=null; S186. LiveInfoDto=null; S186. Name="5.3.3 rotor critical speed"; "' R=re. The.findall (' s186 \. Id=(\ d +); ', source) Print (r) "' [] '1217999465'" ' CodePudding user response:
x=re. The.findall (" (? <=s186. Id=) (\ d *) ", source) CodePudding user response:
reference 1st floor zhulin0909 response: The import re Source="' s186. ChapterId=1211864040; S186. ContentId=1215033291; S186. ContentType=1; S186. DurationInSeconds=927; S186. FreePreview=null; S186. GmtCreate=null; S186. GmtModified=null; S186. Id=1217999465; S186. JsonContent=null; S186. LearnCount=null; S186. LessonId=1214394275; S186. Live=null; S186. LiveInfoDto=null; S186. Name="5.3.3 rotor critical speed"; "' R=re. The.findall (' s186 \. Id=(\ d +); ', source) Print (r) "' [] '1217999465'" ' Hard you, If only modify the pattern=re.com running (r '. *? ContentType=1. *? Id=(\ d +). + name="(. *?) ". *? How to modify the test '), I added one in front of the id \. Or not, CodePudding user response:
Because here is s186. Id and s187, s188 etc. Many of these, CodePudding user response:
The import re The source='s186. ChapterId=1211864040; S186. ContentId=1215033291; S186. ContentType=1; S186. DurationInSeconds=927; S186. FreePreview=null; S186. GmtCreate=null; S186. GmtModified=null; S186. Id=1217999465; S186. JsonContent=null; S186. LearnCount=null; S186. LessonId=1214394275; S186. Live=null; S186. LiveInfoDto=null; S186. Name="5.3.3 rotor critical speed"; ' Pattern=re.com from running (r 's \ d + \. Id=\ d +') Lesson_set=re. The.findall (pattern, source) Print (lesson_set) CodePudding user response:
import re The source='s186. ChapterId=1211864040; S186. ContentId=1215033291; S186. ContentType=1; S186. DurationInSeconds=927; S186. FreePreview=null; S186. GmtCreate=null; S186. GmtModified=null; S186. Id=1217999465; S186. JsonContent=null; S186. LearnCount=null; S186. LessonId=1214394275; S186. Live=null; S186. LiveInfoDto=null; S186. Name="5.3.3 rotor critical speed"; ' Pattern=re.com from running (r 's \ d + \. Id=\ d +') Lesson_set=re. The.findall (pattern, source) Print (lesson_set)