Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Regex Pattern to match all characters before the first ":" in Python

If you want to match all characters before the first ":" in a text, you can use the following pattern:

pattern = r'^[^:]+:'

This pattern uses the negated character class [^:], which matches any character except the colon :. The + quantifier matches one or more occurrences of the characters in the negated character class, and the pattern ends with a colon :. This regex will match any sequence of characters before the first colon in the text.

Regex Pattern to match all characters before the first ":" in Python

If you want to match all characters before the first ":" in a text, you can use the following pattern:

pattern = r'^[^:]+:'

This pattern uses the negated character class [^:], which matches any character except the colon :. The + quantifier matches one or more occurrences of the characters in the negated character class, and the pattern ends with a colon :. This regex will match any sequence of characters before the first colon in the text.