Skip to content
Advertisement

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 first occurrence of -+digits+-: If

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 code. and second input as text

Why does this pandas str.extract pattern work?

I have a dataframe “movies” with column “title”, which contains movie titles and their release year in the following format: The Pirates (2014) I’m testing different ways to extract just the title portion, which in the example above would be “The Pirates”, into a new column. I used pandas Series.str.extract() and found a regex pattern that works, but I’m not

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 word-boundary because 15×20 are two different values.

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 characters which follow http:// or

Extracting codes with regex (irregular regex keys)

I´m extracting the codes from a string list using coming from the title email. Which looks something like: So far what I tried is: My issue is that, I´m not able to extract the code next to the words that goes before [‘PN’, ‘P/N’, ‘PN:’, ‘P/N:’], specially if the code after starts with a letter (i.e ‘M’) or if it

Advertisement