Python Forum
Facing issue in python regex newline match
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Facing issue in python regex newline match
#6
Added r.
import re

input_string =\
""".Myc PGGGGG_UIII_Q9999_AB A0 B11 B22 D1 D2 D3
+ 4I 3B"""

pattern = r'\.(myc|Myc)\s+([a-zA-Z0-9\_\-]+)\s+(.*)\n(.*)'
matches = re.findall(pattern, input_string)[0]
print(matches)
Output:
('Myc', 'PGGGGG_UIII_Q9999_AB', 'A0 B11 B22 D1 D2 D3', '+ 4I 3B') >>> matches[0] 'Myc' >>> matches[-1] '+ 4I 3B'
Reply


Messages In This Thread
Facing issue in python regex newline match - by Shr - Oct-12-2023, 08:54 AM
RE: Facing issue in python regex newline match - by snippsat - Oct-13-2023, 06:51 PM
Python newline match - by Shr - Oct-13-2023, 10:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Last record in file doesn't write to newline gonksoup 3 552 Jan-22-2024, 12:56 PM
Last Post: deanhystad
  issue in using regex akbarza 4 640 Nov-14-2023, 10:00 AM
Last Post: buran
  Failing regex, space before and after the "match" tester_V 6 1,301 Mar-06-2023, 03:03 PM
Last Post: deanhystad
  Regex pattern match WJSwan 2 1,378 Feb-07-2023, 04:52 AM
Last Post: WJSwan
  Python Regex quest 2 2,532 Sep-22-2022, 03:15 AM
Last Post: quest
  Facing problem with Pycharm - Not getting the expected output amortal03 1 911 Sep-09-2022, 05:44 PM
Last Post: Yoriz
  Match substring using regex Pavel_47 6 1,556 Jul-18-2022, 07:46 AM
Last Post: Pavel_47
  CSV to Text File and write a line in newline atomxkai 4 2,826 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  Facing Problem while opening a file through command prompt vlearner 4 2,060 Jan-30-2022, 08:10 AM
Last Post: snippsat
  Match key-value json,Regex saam 5 5,557 Dec-07-2021, 03:06 PM
Last Post: saam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020