Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- x = r"""
- /* comment 1 */
- /***
- comment 2
- ***/
- /*=================
- comment 3
- */
- /*comment 4*/
- /* comment 5
- ***/
- /*****
- comment 6*/
- /* ****
- comment 7*/
- /* **** comment 8
- */
- /* **** comment 9
- *** */
- """
- y = re.compile(r'\/\*(?P<inner>.+?)\*\/', flags=re.UNICODE | re.MULTILINE | re.IGNORECASE | re.DOTALL)
- z = y.findall(x)
- a = [_.splitlines() for _ in z]
- def trashline(line):
- l = line.strip()
- if l:
- l0 = l[0]
- if l.count(l0) == len(l):
- return None
- else:
- return line
- return None
- def consumer(x):
- xlen = len(x)
- if xlen == 1:
- return x
- elif xlen > 2:
- return x[1:-1] # consume the first line /** ... and the last line *///
- elif xlen == 2:
- if trashline(x[0]) is None:
- return x[1]
- elif trashline(x[1]) is None:
- return x[0]
- else:
- raise ValueError("hmmm1")
- raise ValueError("hmm2")
- outs = [consumer(_) for _ in a]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement