Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

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
6 votes
2 answers
395 views

I am trying to write a simple tokenizer for a basic arithmetic calculator. Here's the code: ...
user2338150's user avatar
10 votes
6 answers
1k views

I'm working on a Python script that reads a text file and extracts all the unique email addresses. The code works as intended, it produces the correct output, throws no errors, and I've tested it on ...
rao abdullah's user avatar
6 votes
2 answers
732 views

Here's my (correct) solution to a HackerRank question: Weather Observation Station 8 Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last ...
JTB's user avatar
  • 277
3 votes
1 answer
175 views

I have created a simple text editor with a "replace all" feature. It's meant to be part of a larger project, so it needs to be robust and work reliably across various scenarios. Please ...
Mori's user avatar
  • 197
5 votes
1 answer
137 views

This is my first Rust project (I'm primarily a C guy). I want to know if my code is properly idiomatic (Rusty?). Also, are there any inefficiencies? The code defines an iterator (...
Daniel Walker's user avatar
0 votes
0 answers
93 views

I want to share my invention, which allows you to use only one RegEx, which will search for substrings in a string with a certain condition. If you want, call it a RegEx loop that didn't exist before! ...
Raf's user avatar
  • 9
4 votes
1 answer
100 views

I've made a code in Python 3 which converts a polynomial with integer coefficients (in simplified integer form) from string form to a list of tuples of the form (coefficient, exponent, variable). It ...
Sam's user avatar
  • 147
2 votes
2 answers
159 views

I would like to know if there is a better regex to match all worded numbers from 1 to 99. With "better" I mean shorter with same performance, OR faster. I came up with this. I can't do ...
Bobby234's user avatar
1 vote
1 answer
68 views

I have a Polars dataframe in which the cells contain a sequence of single digits as a string of characters, and I want to find the number of differences between the single-digits elements of the ...
Josh9999's user avatar
5 votes
1 answer
391 views

I attempted to implement a python version of this function in my previous question. Given a regular expression with range(s) of alphabets/numbers, the function will expand the brackets and return a ...
nightstand's user avatar
2 votes
0 answers
111 views

I tried writing a short function that expands brackets [] within a regular expression. Given a regular expression, the function will expand the brackets and return ...
nightstand's user avatar
3 votes
1 answer
140 views

I have written code to manage a string and retrieve from it a dictionary which must contain pairs key-value dependent from the string. To be more clear I'll show ...
User051209's user avatar
2 votes
1 answer
104 views

I've implemented a function that creates a multiple regular expressions predicate. The idea behind the predicate is combining regular expressions using the disjunction operator ...
terrorrussia-keeps-killing's user avatar
1 vote
1 answer
181 views

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
  • 5,044
2 votes
1 answer
86 views

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
1k views

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

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

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
3 votes
2 answers
171 views

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
82 views

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
  • 461
4 votes
4 answers
3k views

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
108 views

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
6 votes
2 answers
241 views

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
  • 63
4 votes
1 answer
201 views

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
  • 26.2k
1 vote
2 answers
349 views

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

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
217 views

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
270 views

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
  • 435
1 vote
1 answer
5k views

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

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
624 views

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
1 vote
1 answer
193 views

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
335 views

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
147 views

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
145 views

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
85 views

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
153 views

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

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
275 views

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

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
  • 281
1 vote
1 answer
263 views

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
420 views

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
2 votes
1 answer
1k views

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
  • 107
3 votes
1 answer
228 views

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
717 views

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
1 vote
2 answers
146 views

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
  • 273
7 votes
7 answers
3k views

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
  • 3,033
1 vote
1 answer
152 views

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
104 views

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

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

1
2 3 4 5
18