Skip to content

Tag: regex

Regex to extract usernames/names from a string

I have strings that includes names and sometime a username in a string followed by a datetime stamp: I want to extract the usernames from this string: I have tried different regex patterns the closest I came to extract was following: Using the following regex pattern: Answer You may get all text up to the fir…

is it possible to use “input variables” in custom order

I’m new in python and regex. I’m trying to make a one-line regex implementation. In first input want to take a text to check, and for second input the regex pattern. Is it possible in python to achieve that? edit: to make question clearer; due to expression console takes first input as regex into …

Match non-capturing group multiple times

I tried really hard to make a good title, but I’m not sure if I’m asking this right. Here’s my best attempt: I’m using Python’s flavor of regex I need to match numbers using named groups: but should not match: my best attempt so far has been: I’m using [sa-z] instead of a w…

Regular expression for removing all URLs in a string in Python

I want to delete all the URLs in the sentence. Here is my code: But a URL with “http” is still left in the sentence. How can I fix it? Answer One simple fix would be to just replace the pattern https?://S+ with an empty string: This prints: My pattern assumes that whatever non whitespace character…