Skip to main content

Questions tagged [regex]

Regular expressions are a declarative language, mainly used for pattern matching within strings. Please include a tag specifying the programming language you are using, together with this tag.

Filter by
Sorted by
Tagged with
1 vote
1 answer
124 views

Function, which replaces consecutive white-space with a single white-space

Task-description: Implement a function, which returns a string with all consecutive whites-spaces replaced as a single-space. Example: "a[space][space][space]b[space][space][space]c" shall ...
michael.zech's user avatar
  • 4,294
2 votes
1 answer
42 views

Multiple regexp replace in string

I made a function that prompts me for values of variables (formatted %^{var1}) it found in a string and fills in said values. ...
my_display_name's user avatar
9 votes
2 answers
946 views

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Task description: Write a function, which counts the letters, spaces, number and special characters in string. My implementation: ...
michael.zech's user avatar
  • 4,294
6 votes
1 answer
1k views

Username Validation RegExp

Working through the freeCodeCamp JavaScript curriculum and I found this RegExp task surprisingly tricky (maybe I just don't use RegExp very much). The parameters are: Usernames can only use alpha-...
Christopher Fimbel's user avatar
4 votes
4 answers
2k views

Matching words from a text with a big list of keywords in Python

I implemented the following code to retrieve medication names from a given text (prescription_text in the code). It works by matching words in the text with a list ...
cuzureau's user avatar
  • 191
2 votes
2 answers
123 views

Algorithm to compare OAuth2 Rich Authorization Requests

Authorization Requests spec defines new authorization_details parameter. The authorization server have to somehow compare this parameter to decide whether client ...
Szyszka947's user avatar
1 vote
1 answer
44 views

Check for valid dates for all steps of the date

I want to check if a given string is a date of the form YYYY-mm-dd, including all the steps in it, i.e. YYYY-mm-dd, YYYY-mm and YYYY. For example, all of the following dates are valid: ...
pileup's user avatar
  • 421
4 votes
4 answers
3k views

A function that uses a regex to parse date and time and returns a datetime object

The code works, but I think can be simplified, I don't know which specific steps, but my version seems to me quite complicated I build a function that takes a specific string format and returns a <...
Andrea Ciufo's user avatar
0 votes
1 answer
75 views

Parsing shortcodes out of a string

I wrote this shortcode parsing and it runs in \$O(N^2)\$. Is there a way to better optimize this? ...
ericraio's user avatar
  • 151
4 votes
2 answers
155 views

Sort todo.txt items by due date in Python 3

I am using the following format for my task management: https://github.com/todotxt/todo.txt Do some stuff +uni due:2022-12-31 Write some paper +uni due:2023-01-10 ...
Tomas's user avatar
  • 43
2 votes
1 answer
138 views

Implementing Linux style file name wild cards on Windows 10 PowerShell

Implementing Linux style file name wild cards on Windows 10 PowerShell While implementing an objected oriented wc on Windows 10 in visual studio C++ I implemented a recursive file search with a weak ...
pacmaninbw's user avatar
  • 23.8k
1 vote
2 answers
285 views

Replacing banned words from a given text

The following algorithm is used to find a word from Blacklisted words in a string (called text) and replace these words with censored text, as shown in the example. Example: ...
TomaszOleszko's user avatar
10 votes
4 answers
4k views

Determine age from given birth date

So this is my first ever attempt so it's obviously bad. There has to be a better way to do this. A big thing I haven't implemented is trying to guarantee the structure of the input(i.e making sure ...
malibooyah's user avatar
1 vote
2 answers
166 views

Parse list of UserPrincipal objects into custom class

I'm wondering how I could optimize this method that takes in a list of UserPrincipal objects, filters them by Regex and inserts the new class instance into a list. It takes 4 to 5 seconds for an input ...
mvi2110's user avatar
  • 11
3 votes
2 answers
220 views

Thread-safe cached compiled Regex

I have a use case where I want to keep a pre-compiled regex, cached, for performance reasons, but the regex pattern also needs to be updated infrequently. Instances of CachedRegexFilter class will be ...
Dexter's user avatar
  • 415
1 vote
1 answer
4k views

A python script to download video from a website

I wrote this script for gaining experience, this script takes in a website link (NSFW) and download the video on that site. It uses regular expressions to parse the website source code to extract urls ...
User's user avatar
  • 201
4 votes
2 answers
1k views

Add a number to a file name if does not exist or increase the number if it exist

I'm currently working on a solution to add a number to a file name if the number does not exist or increase de number by one if the number exist. For instance if you input "filename.jpeg" ...
Mario's user avatar
  • 41
0 votes
1 answer
554 views

Using a RegEx to create a UUID string

I'm writing a Discord bot that sometimes requires a Minecraft account UUID to be looked up so this is the function (and MWE) I have written to do this. ...
Jake's user avatar
  • 131
0 votes
1 answer
163 views

Password policy with regex and zxcvbn

This code snippet shows an implementation of a password policy check. - The method composition uses regex to verify that the password meets composition criteria (at least one number, one special ...
questıoner's user avatar
2 votes
1 answer
289 views

Text splitter using Regular Expressions in Python

I have been provided a text splitter class that will take a text input and use re.sub to make replacements when matches are found and also splits sentences up and stores them in a list. I had an idea ...
JackWeir's user avatar
2 votes
1 answer
106 views

Newspaper Bill Calculator CLI with Python (1 of 3, Core)

Code is posted after explanation. Due to the size of the project, this is being posted in three separate posts. This also ensures each post is more focused. Post 2 of 3, CLI: Newspaper Bill ...
eccentricOrange's user avatar
2 votes
2 answers
113 views

Regex and pandas to read forecast sky condition string

DataFrame methods to parse the sky condition from a terminal aerodrome forecast. A line in a taf can report zero-eight cloud layers. Cloud layers are required in predominate lines, and optional in ...
Jason Leaver's user avatar
3 votes
1 answer
51 views

Replace badly formatted questionnaires in a document using regex

I have rather badly formatted questionnaires (i.e. ordered lists) in a bunch of documents that I want to clean up and replace the current version with the cleaned-up version. Example text ...
Blue482's user avatar
  • 131
2 votes
1 answer
124 views

Regex pattern matching to generate pandas multi index

Mostly just looking for a review of my regex and implementation of capture groups. its something I've been working to improve. The indexes have somewhat of a pattern to them of being.... ...
Jason Leaver's user avatar
5 votes
1 answer
1k views

Breaking Bad name generator

I've created a script to print all periodic table symbolic permutations of a string. As seen in the opening credits of each episode of Breaking Bad: © 2010-2022 AMC Networks Entertainment LLC. ...
Freddy Mcloughlan's user avatar
2 votes
1 answer
235 views

Extract regular words from string but retain all other elements and record their type

This snippet processes every regular (\w+) word in a text and reinserts the processed version: ...
Alex Povel's user avatar
  • 1,226
7 votes
2 answers
1k views

Automate the Boring Stuff CH 7: password strength test

This exercise comes from Automate the Boring Stuff Ch 7. The assignment is to use regular expressions to test the strength of a password. Password must be >= 8 characters, contain at least one ...
Ramza's user avatar
  • 171
1 vote
1 answer
204 views

Regex to capture possible US date entries

The Problem I'm relying on plaintext entry to capture dates. End users are urged to enter as MM-DD-YY, but it'll be great to account for as many possibilities. US ...
user2402616's user avatar
3 votes
3 answers
340 views

Regex to extract portions of string about shipment

The Problem I'll be extracting up to 4 parts of a String that come from user-input. All 4 parts need to be in order i.e. (1-4) below in that order The first capturing group is required and the last ...
user2402616's user avatar
1 vote
1 answer
1k views

Replace Multiple Matches with different Values

I want to replace multiple matches of a Regex with different values from a map. I have for example the following string #id#_#date#_#value#_additional_text. I now ...
Kevin's user avatar
  • 147
3 votes
1 answer
176 views

Remove unwanted characters at the end of a string

I want to make this code better , its works now, but i think it can be better , i have a hook and one property is onChange that get value and can setState and return that value for value of input , in ...
tmohammad78's user avatar
3 votes
2 answers
618 views

Replace function for C++

I'm learning regex for c++, and tried to make a simple function. It is very small but I'm satisfied, because this is the first time I managed to pass function as argument. This is a replace function. ...
ihsan's user avatar
  • 153
0 votes
2 answers
114 views

Python function for finding if all substrings exist in a string in sequence

I want to find if all of a list of substrings exist in a string, in the correct order (with or without spaces between them), it seems to be a good use for regex. I think I need to build a regex ...
JeffUK's user avatar
  • 213
7 votes
7 answers
3k views

DnD Die in Java with regex

For my game I need to roll some values with a die. A die is formally described as: nDs[+a] n amount of die (optional, 1 of not set, zero must be set explicitly) D ...
Martin Frank's user avatar
  • 2,838
1 vote
1 answer
125 views

using pandas and numpy to parse dirty .csv

I'm relatively new to Python have been writing for a few months now. I've started a Pandas Numpy project that starts with parsing large and somewhat sloppy formatted textfile, its not exactly csv but ...
Jason Leaver's user avatar
0 votes
2 answers
62 views

Test strings with a lot of regular expressions

I've a list of strings and a list of regular expressions. I need to categorize each string to get what type of string it is based on regex. This is my code: ...
Katherine Maurus's user avatar
1 vote
1 answer
3k views

Regex detect URL without http(s):// and www

I want to locate urls without protocols in the text, and then add the protocol before them. This means I don't want urls that begin with http(s):// or ...
tnthpp66's user avatar
8 votes
3 answers
1k views

Filter out ambiguous bases from a DNA sequence

I have this function: ...
Paulo Sergio Schlogl's user avatar
7 votes
1 answer
403 views

Stop cheating on home exams using python

Background I am teaching a course at university level, and have lately been working on creating a home exam for my students. However, the institute has given clear instructions that collaboration is ...
N3buchadnezzar's user avatar
2 votes
1 answer
313 views

Find if a dataset of words contains any words containing all vowels by using exactly 5 calls to str_detect

Take the words dataset from stringr. An R4DS exercise challenges the reader to check if there are any words in that dataset that ...
J. Mini's user avatar
  • 127
1 vote
1 answer
2k views

simplifying regex expression for timestamp

I was wondering if it's possible to simplify this regex string (JS): ...
Tom's user avatar
  • 241
4 votes
1 answer
356 views

Regex to match several slightly different strings

I work with a charity that does a number of jobs, more than 100, less than 1000 a year. Jobs are identified with a year, and an up to 3 digit serial number, so ...
Neil_UK's user avatar
  • 343
7 votes
5 answers
145 views

readable validation with python regex and simple logic

I have come with such a code for checking IP addresses. But would like to know how clean and good it is from 1 to 10. What I care about are readability and simplicity. Please give me any feedback. ...
Jon Grey's user avatar
2 votes
1 answer
60 views

String formatting

My requirement is to format the input values to a particular format as "##.###/##.###" Example - My input value can have alphabets, alphanumeric, numeric Expired -- > if alphabet, output ...
user241512's user avatar
0 votes
1 answer
1k views

RegEx sentence-splitting madness. Mad genius?

I inherited the following regex: /[^.!?\s][^.!?\n]*(?:[.!?](?!['"]?\s|$)[^.!?]*)*[.!?]?['"]?(?=\s|$)/g This regex is used to split sentences, and is ...
Daniël van den Berg's user avatar
5 votes
2 answers
6k views

Date Detection Regex in Python

I worked on a problem from Automate the Boring Stuff Chapter 7: Write a regular expression that can detect dates in the DD/MM/YYYY format. Assume that the days range from 01 to 31, the months range ...
jp207's user avatar
  • 173
1 vote
1 answer
76 views

Doing a re.findall with pcre library

I am trying to get an array of all regex matches. For example, something like this: ...
David542's user avatar
  • 409
3 votes
1 answer
88 views

Regex with comments

The below is to parse a lisp expression (doing as much as possible in 'one go'). How does it look, and what can be improved? ...
samuelbrody1249's user avatar
2 votes
0 answers
103 views

Is there a better pattern to match those words with regex?

Hello StackExchange community, I am curious if there is a better solution than mine for this exercise below: Enter a regex that matches all the items in the first column (positive examples) but none ...
Spiros Gkogkas's user avatar
2 votes
1 answer
63 views

Martix of Counts of Regex Hits Over a List of Strings

I have: A dataframe with Identifiers (TermId) and Search Terms (SearchTerm). A list of text strings (...
Tyler Rinker's user avatar

1
2 3 4 5
18