#πŸ”’ Regex to find up to three repeating characters, followed by a space

16 messages Β· Page 1 of 1 (latest)

tranquil nova
#

I can't figure it out, and neither can ChatGPT 😝.

"## Hello ### World ###### Test"

should return ['##', '###']

Please help! Thanks.

edit: I said characters, but specifically I want '#'

cerulean eagleBOT
#

@tranquil nova

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

delicate pelican
west lagoon
#

You might need some negative lookahead.

#

Caveat emptor: I'm not a regex person.

#

No, negative lookbehind.

#
'#{1,3}(?<!#{4})(?= )'```
#

Negative lookbehind and positive lookahead.

#

Because you didn't want the spaces.

#

Now...this gets the result...but.

#

I don't know how well it's going to hold up to more robust testing.

#

I don't know if this is good regex or crap regex.

#

But there's my go at it.

#

@tranquil nova

cerulean eagleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.