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.
870 questions
6
votes
2
answers
395
views
Operator associativity while writing tokenizer using regex match
I am trying to write a simple tokenizer for a basic arithmetic calculator. Here's the code:
...
10
votes
6
answers
1k
views
Extract unique email addresses from a text file
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 ...
6
votes
2
answers
732
views
Weather Observation Station 8 query
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 ...
3
votes
1
answer
175
views
Bulk Text Replacer
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 ...
5
votes
1
answer
140
views
File system regex searcher
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 (...
0
votes
0
answers
94
views
Pure loop in RegEx to find the substrings with condition
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! ...
4
votes
1
answer
100
views
Polynomial parsing using regular expressions in Python
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 ...
2
votes
2
answers
161
views
Faster regex to match all worded numbers from 1 to 99
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 ...
1
vote
1
answer
69
views
Match pattern in Polars (Python) native API vs the slow map_elements
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 ...
5
votes
1
answer
393
views
Python function to expand regex with ranges
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 ...
2
votes
0
answers
111
views
R function to expand range of numbers/alphabets in a regex
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 ...
3
votes
1
answer
141
views
Build a dictionary from a string by the extraction of data from all the pairs <TAG|VAL> contained inside the string and clean string from TAGs
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 ...
2
votes
1
answer
105
views
Combining multiple regexps using the `|` operator and grouping the regexps by their flags
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 ...
1
vote
1
answer
181
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 ...
2
votes
1
answer
87
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.
...