Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regular expression
#1
Str1 = [Math1] Total marks [ End Math1] [Data] Total data [ End Data ]
I am trying to extract the paragraph like using re.

json =
{"Math1":[
]
"Data":[
]

Thanks.
Reply
#2
Does your string format allow nesting? E.g. Can one data block include math block or data block? If so, you are likely needed a parser and the problem cannot be solved using one or two specific regular expressions only. However, regular expressions can help you to implement the parser.
One hacky way is to use regular expressions to replace [math] [end math] and data blocks to something like <math count="1"> </math>, to turn your string into valid xml-string and use, e.g. lxml library to parse it and extract the data.
Also, take a look at pyparsing module.
Reply
#3
input_text = "system computer laptop"
input_text = "mobile sim card"

We retrieve first:
text = "system computer laptop"

how do we match using import re

output = re.search(input_text, text)
print(output)

case ii.  we need to match text = "mobile sim card" and print it "mobile sim card"
output = re.search(input_text, text)
print(output)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Regular Expression stahorse 9 1,472 Jul-31-2023, 01:20 PM
Last Post: Will_Robertson
  regular expression pramod 1 1,524 Jul-10-2020, 06:38 AM
Last Post: karkas
  regular expression pramod 6 2,927 Jul-04-2020, 04:58 AM
Last Post: pramod
  regular expression pramod 4 2,044 Jun-16-2020, 02:01 AM
Last Post: pramod

Forum Jump:

User Panel Messages

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