I would like to extract lines in between '*Node\n' and '*Element, type=S4R\n' from the following text using regex.
text ="""**
*Part, name=Part-2
*Node
1, 0.25, 0.5, 0.75
2, 0.25, 0., 0.75
1416, 0.200000003, 0., 0.0500000007
*Element, type=S4R
1, 1, 21, 357, 46
2, 21, 22, 358, 357
*Nset, nset=_PickedSet24, internal, generate
1, 1416, 1
**"""
I have tried re.findall(r"\*Node\s([\s\S]+)\*\w", text) and re.findall(r"(?<=\*Node\s)([\s\S]+)(?=\*)", text) but not able to filter out the end portion of the text. I'm getting output:
[' 1, 0.25, 0.5, 0.75\n 2, 0.25, 0., 0.75\n 1416, 0.200000003, 0., 0.0500000007\n*Element, type=S4R\n 1, 1, 21, 357, 46\n 2, 21, 22, 358, 357\n*Nset, nset=_PickedSet24, internal, generate\n 1, 1416, 1\n*']
However, if I try re.findall(r"(?<=name\s)([\s\S]+)(?=\selon)", text1) & re.findall(r"name\s([\s\S]+)\selon", text1) for the following code, I do get ['isn,t'] as desired.
text1 = """my name isn,t\nelon *nestla"""
EDIT full text is the following, there are multiple such patches to extract and I can end the patches with *Element always
text = """** PARTS
**
*Part, name=Part-2
*Node
1, 0.25, 0.5, 0.75
2, 0.25, 0., 0.75
1416, 0.200000003, 0., 0.0500000007
*Element, type=S4R
1, 1, 21, 357, 46
2, 21, 22, 358, 357
*Nset, nset=_PickedSet24, internal, generate
1, 1416, 1
*End Part
**
*Part, name=plate#Part-1
*Node
1, -0.449999988, -0.477499992, 0.
2, -0.400000006, -0.477499992, 0.
121, 0.0500000007, 0.0225000009, 0.
*Nset, nset=_PickedSet2, internal, generate
1, 121, 1
*End Part
**
**"""
\*Node\r?\n([\s\S]+)\r?\n\*Element, type=S4Rregex101.com/r/ilpWYk/1regex = r"^\*Node\r?\n((?:(?!\*\w).*\r?\n)*)\*\w.*"and then use re.findall. See ideone.com/DFel7r