Matching-at-the-start-and-end-of-strings extended

hint for Conditional Operation usage in regex

# Attempted to select only pdf or videos as tags
#please open in raw format else u will not be able to see some regex

#----Code Below------------#
#pattern to select titles starting with tag  pdf or videos
pattern = r"(?:^\[video\]|^\[pdf\])"
#pattern to select titles ending with tag  pdf or videos
pattern_end = r"(?:\[video\]$|\[pdf\]$)"
#pattern to select titles starting with any tag
pattern_1 = r"^\[\w+\]"
#pattern to select titles ending with any tag
pattern_2 = r"\[\w+\]$"
beginning_count = titles[titles.str.contains(pattern_1)].count()
ending_count = titles[titles.str.contains(pattern_2)].count()
beginning_count_pdf_videos = titles[titles.str.contains(pattern)].count()
ending_count_pdf_videos = titles[titles.str.contains(pattern_end)].count()
5 Likes

Hey @eashwary,

Can you please elaborate a little more? It’s difficult for me to understand what you want to share.

Are you asking a question?

Is it the same as what you shared here?

At first time I tried to submit but having issues, so tried resubmitting. I think because of that post came 2 times.

Its not question.

I just wanted to share how to select only tags having pdf or videos , not . How to do that , I shared.

2 Likes

Hi @eashwary,

Thank you for sharing! You can surround your code with 3 backticks ``` like this to format it.

I am going ahead and deleting the duplicate post, let me know if you need any further help. :slightly_smiling_face:

Best,
Sahil

Good source for non capture group

Non Capturing Groups

“Or” in regular expressions ||

1 Like

I come for this!! thank you @eashwary :smile:

Hello there
What’s the point of putting ?: in the beginning of the regex?