Rules:
- “trr” must appear in the text
- “abc” and “cba” are representing as unknown characters or/and symbols and unknown amount of letters.
- “trr” leaves a copule of unknown characters or/and symbols behind or/and in front until the first “:” is found from either direction.
- The text formatted with “abc” and “cba”, and will be in the following structures: “trr:abc:cba” or “abc:cba:trr”
- The final goal is to find “abc” and “cba”
Here is what I tried to do:
import re
lines = [
"ksad29://trr/h4fds1:askgh85k_Sg:J@(SK!)",
"dfg326f://trr:S)@_Skasfm.c:js_1",
"trr/(sa-):sj_14!:!lsx.1",
"trr:js21s:x2491",
"askgh85k_Sg:J@(SK!):ksad29://trr/h4fds1",
"S)@_Skasfm.c:js_1:dfg326f://trr",
"sj_14!:!lsx.1:trr/(sa-)",
"js21s:x2491:trr",
"ksad29://xee/h4fds1:askgh85k_Sg:J@(SK!)",
"dfg326f://xee:S)@_Skasfm.c:js_1",
"xee/(sa-):sj_14!:!lsx.1",
"xee:js21s:x2491",
"askgh85k_Sg:J@(SK!):ksad29://xee/h4fds1",
"S)@_Skasfm.c:js_1:dfg326f://xee",
"sj_14!:!lsx.1:xee/(sa-)",
"js21s:x2491:xee"
]
for line in lines:
search = "trr"
match = re.search(fr"{search}.*?:([^:]+):([^:]+)", line)
if match:
print(f'"{line}" | Found | "{match.group(1)}", "{match.group(2)}"')
else:
print(f'"{line}" | Not Found')
Results:
"ksad29://trr/h4fds1:askgh85k_Sg:J@(SK!)" | Found | "askgh85k_Sg", "J@(SK!)"
"dfg326f://trr:S)@_Skasfm.c:js_1" | Found | "S)@_Skasfm.c", "js_1"
"trr/(sa-):sj_14!:!lsx.1" | Found | "sj_14!", "!lsx.1"
"trr:js21s:x2491" | Found | "js21s", "x2491"
"askgh85k_Sg:J@(SK!):ksad29://trr/h4fds1" | Not Found
"S)@_Skasfm.c:js_1:dfg326f://trr" | Not Found
"sj_14!:!lsx.1:trr/(sa-)" | Not Found
"js21s:x2491:trr" | Not Found
"ksad29://xee/h4fds1:askgh85k_Sg:J@(SK!)" | Not Found
"dfg326f://xee:S)@_Skasfm.c:js_1" | Not Found
"xee/(sa-):sj_14!:!lsx.1" | Not Found
"xee:js21s:x2491" | Not Found
"askgh85k_Sg:J@(SK!):ksad29://xee/h4fds1" | Not Found
"S)@_Skasfm.c:js_1:dfg326f://xee" | Not Found
"sj_14!:!lsx.1:xee/(sa-)" | Not Found
"js21s:x2491:xee" | Not Found
I’ve provided couple of versions of text that might appear, with the expected results:
-
“ksad29://trr/h4fds1:askgh85k_Sg:J@(SK!)” | Found | “askgh85k_Sg”, “J@(SK!)”
-
“dfg326f://trr:S)@_Skasfm.c:js_1” | Found | “S)@_Skasfm.c”, “js_1”
-
“trr/(sa-):sj_14!:!lsx.1” | Found | “sj_14!”, “!lsx.1”
-
“trr:js21s:x2491” | Found | “js21s”, “x2491”
-
“askgh85k_Sg:J@(SK!):ksad29://trr/h4fds1” | Found | “askgh85k_Sg”, “J@(SK!)”
-
“S)@_Skasfm.c:js_1:dfg326f://trr” | Found | “S)@_Skasfm.c”, “js_1”
-
“sj_14!:!lsx.1:trr/(sa-)” | Found | “sj_14!”, “!lsx.1”
8 . “js21s:x2491:trr” | Found | “js21s”, “x2491”
- “ksad29://xee/h4fds1:askgh85k_Sg:J@(SK!)” | Not Found
- “dfg326f://xee:S)@_Skasfm.c:js_1” | Not Found
- “xee/(sa-):sj_14!:!lsx.1” | Not Found
- “xee:js21s:x2491” | Not Found
- “askgh85k_Sg:J@(SK!):ksad29://xee/h4fds1” | Not Found
- “S)@_Skasfm.c:js_1:dfg326f://xee” | Not Found
- “sj_14!:!lsx.1:xee/(sa-)” | Not Found
- “js21s:x2491:xee” | Not Found
A more visual version illustrating how the text is constructed using “abc”, “cba”, “bbb” and “txx” (“abc”, “cba”, “bbb” and “txx” are representing unknown characters or/and symbols and unknown amount of letters):
- “bbb://trr/txx:abc:cba” | Found | “abc”, “cba”
- “bbb://trr:abc:cba” | Found | “abc”, “cba”
- “trr/txx:abc:cba” | Found | “abc”, “cba”
- “trr:abc:cba” | Found | “abc”, “cba”
- “abc:cba:bbb://trr/txx” | Found | “abc”, “cba”
- “abc:cba:bbb://trr” | Found | “abc”, “cba”
- “abc:cba:trr/txx” | Found | “abc”, “cba”
- “abc:cba:trr” | Found | “abc”, “cba”
- “bbb://xee/txx:abc:cba” | Not Found | “abc”, “cba”
- “bbb://xee:abc:cba” | Not Found | “abc”, “cba”
- “xee/txx:abc:cba” | Not Found | “abc”, “cba”
- “xee:abc:cba” | Not Found | “abc”, “cba”
- “abc:cba:bbb://xee/txx” | Not Found | “abc”, “cba”
- “abc:cba:bbb://xee” | Not Found | “abc”, “cba”
- “abc:cba:xee/txx” | Not Found | “abc”, “cba”
- “abc:cba:xee” | Not Found | “abc”, “cba”