Skip to content

Instantly share code, notes, and snippets.

@Mikeysax
Last active June 17, 2021 14:58
Show Gist options
  • Save Mikeysax/31e24d01f7b4a100bdcb43695e35a054 to your computer and use it in GitHub Desktop.
Save Mikeysax/31e24d01f7b4a100bdcb43695e35a054 to your computer and use it in GitHub Desktop.
Find Values
# Find all VAL instances that are directly after and instance of XX
# if a VAL has a VAL inbetween itself and XX, it does not meet the above criteria
# A VAL instance can have characters in between XX and VAL but not another XX or VAL
str = """Lorem ipsum dolor sit amet, consec[VAL1]tetur adipiscing elit. XX et sapien eu risus pretium mollis.
Fusce diam lacus, ornare quis dapibus in, porttitor non risus. Curabitur eleifend libero et XX venenatis.
Donec malesuada lobortis ex, eget cursus[VAL2] lectus interdum a. [VAL43]Aliquam iaculis magna nec rXXisus dapibus lobortis.
Aliquam aliquam magna et fringilla tincidunt. Proin urna risus, lacinia eu quam in, venenatis aliquet magna.
Mauris at ex id justo lacinia maximus id id mauris. Phasellus at dolor convallis, pellentesque leo maximus, vulputate diam.
In hac habitasse platea dictumst. Nullam feugiat venenatis congue. Suspendisse vestibulum ornare pretium.
Sed quis [VAL24]tortor lobortis, dignissim mi eu, consequat justo. Duis nunc ipsum, aliquet semper sem vitXXae, iaculis ultrices sem.
Duis rutrum porttitor dui. Suspendisse feugiat nulla ac diam tincidunt convallis.
Vestibulum qua[VAL5]m urna, mattis vel ma[VAL6]gna quis, pretium placerat leo.
Fusce ullaXXmcorper[VAL7] luctXXus porttitor.
Vestibulum ante ipsum primis in faucibus orci luctu[VAL18]s et ultrices posuere cubilia Curae; Pellent[VAL9]esque laoreet laXXcus nunc,
eget bibendum leo efficitur nec. Sed tincidunt turpis a ex eleifend congue.
Praesent blandit mi nec metus convallis tempus pulvinar eu odio.
Nullam mollis tellus urna, ac dign[VAL10]issim neque dapibus nec.
Donec rhoncus maximus metus, ornare rhoncus metus pharetra nec. Donec congue nisl non."""
def find_values(string)
##
end
find_values(str)
# Expected Output
# ["[VAL2]", "[VAL24]", "[VAL5]", "[VAL7]", "[VAL18]", "[VAL10]"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment