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
2 votes
1 answer
60 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 ...
user avatar
2 votes
1 answer
55 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 ...
user avatar
2 votes
2 answers
81 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 ...
user avatar
3 votes
0 answers
35 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 ...
user avatar
  • 131
2 votes
1 answer
49 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.... ...
user avatar
5 votes
1 answer
234 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. ...
user avatar
2 votes
1 answer
72 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: ...
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 ...
user avatar
  • 117
1 vote
1 answer
32 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 ...
user avatar
3 votes
3 answers
183 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 ...
user avatar
1 vote
0 answers
94 views

C++ Regex Replace Multiple Matchs with different Values

I want to replace multiple matches of an Regex with different values from a map. I have for example the following string #id#_#date#_#value#_additional_text. I now ...
user avatar
  • 111
0 votes
0 answers
42 views

Parse a user's time specification (wide choice of formats)

Scenario I've got a one-line user input command that I need to handle and breakdown with regex. Example: In 7:00 pm In MM/DD, This is suppose to check in on a certain day In 23:11 In -1 Current day ...
user avatar
  • 1
3 votes
1 answer
118 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 ...
user avatar
0 votes
0 answers
16 views

make an array of cells from formula like in excel with javascript?

I'm working on stylesheet in Excel, and I've made this function of makeCells is there a better way of doing it. I've tried regex to get two cells ...
user avatar
3 votes
2 answers
87 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. ...
user avatar
  • 53
0 votes
2 answers
57 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 ...
user avatar
  • 213
0 votes
0 answers
43 views

Why is this MongoDB query so slow in comparison to python + in general?

There are 1.3M documents in my collection (5.0 and hosted directly on mongodb.com) and there is an index on "topic" and a combined index on "topic" and another field. However the ...
user avatar
  • 165
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 ...
user avatar
  • 2,392
1 vote
1 answer
79 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 ...
user avatar
0 votes
2 answers
55 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: ...
user avatar
0 votes
0 answers
98 views

Format pem key one line string in JS

I receive .pem key as one string which needed to be formatted to be able to create signature ...
user avatar
0 votes
1 answer
193 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 ...
user avatar
0 votes
0 answers
39 views

Normalizing URL pathnames in TypeScript

I’m writing backend code for a website, and I’ve been surprised by the fact that a URL’s path component isn’t normalized at all, retaining trailing and duplicate slashes (...
user avatar
8 votes
3 answers
997 views

Filter out ambiguous bases from a DNA sequence

I have this function: ...
user avatar
0 votes
0 answers
38 views

Optimize Javascript User Mentioning

I want to replace every div with the class mention. The text should then be parsed and all the parts with ...
user avatar
7 votes
1 answer
212 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 ...
user avatar
2 votes
1 answer
146 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 ...
user avatar
  • 61
1 vote
1 answer
337 views

simplifying regex expression for timestamp

I was wondering if it's possible to simplify this regex string (JS): ...
user avatar
  • 241
4 votes
1 answer
180 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 ...
user avatar
  • 343
7 votes
5 answers
121 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. ...
user avatar
2 votes
1 answer
52 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 ...
user avatar
0 votes
1 answer
244 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 ...
user avatar
5 votes
2 answers
4k 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 ...
user avatar
  • 143
3 votes
1 answer
61 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? ...
user avatar
2 votes
0 answers
76 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 ...
user avatar
2 votes
1 answer
53 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 (...
user avatar
0 votes
1 answer
38 views

Grabbing resolution and offset from xrandr

(using GNU sed) I want to grab some output from xrandr and leave out everything but the resolution and offset. Input: ...
user avatar
2 votes
1 answer
82 views

Sanitize user-supplied HTML with Python and Regular Expressions

I have a product that needs to have users put content in a form that potentially contains HTML and display it back to other users. I'd like to mitigate the risk as much as possible, and I can limit ...
user avatar
  • 21
0 votes
1 answer
42 views

function to check if anchor tags contain href attributes with 301

I made this function to test if the content has 301 redirections.. Please can you help me optimize it better because it's too slow ...
user avatar
4 votes
3 answers
460 views

use regex to separate a list of serial numbers into multiple lists with matched prefix

The question comes from How to separate a list of serial numbers into multiple lists with matched prefix? on Stack Overflow. Input: ...
user avatar
1 vote
1 answer
86 views

Class showing a format similar to var_dump v1.0.5

First of all I must thank for the help given in the previous post: Class showing a format similar to var_dump RC5 Version I have it deployed in a early versio v1.0.5: https://github.com/arcanisgk/BOH-...
user avatar
2 votes
1 answer
29 views

Validator and Sanitizer for HTML 5 attribute regex according to current HTML living standard

According to https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 an HTML 5 attribute name is defined like this: Attribute names must consist of one or more characters other than controls, ...
user avatar
  • 137
3 votes
2 answers
180 views

Downloading and parsing research papers

I am trying to write a script which gets a research paper from a website by calling their API and then traverse it sentence-wise with some conditions. The paper is accessible in XML format. I am ...
user avatar
  • 31
0 votes
2 answers
88 views

Parse file and make output in custom List [closed]

I have a file output like this and want to do parsing and put the output into a List. The biggest problem here is the name of a wake-lock which appears after ID and runtime, in some cases, it contains ...
user avatar
3 votes
4 answers
241 views

A simplified regular expression matcher

I am working my way through some code challenges — partly to improve my problem solving, but also to improve my code quality. I think my current (fully-functional) solution to a challenge is pretty ...
user avatar
  • 33
2 votes
0 answers
52 views

Request for help to speed up batch program for 17,000 TXT files

I have over 17,000 pages that have been scanned (for a local history archive) which I have OCRed using Tesseract to individual TXT files. I want to be able to search/locate every page containing a ...
user avatar
  • 21
2 votes
2 answers
95 views

Replace string based on multiple rules, don't replace same section twice

Given a 2-column CSV dictionary file that contains translation of certain words, this c# code needs to replace the first occurrence of a word in the dictionary. Once a segment of string has been ...
user avatar
  • 183
2 votes
1 answer
49 views

Optimizing a script that switches function arguments in code files

I made a quick script, that inputs file paths(made for C files), function names and 2 indexes. The script goes over all of the files and switches the indexes of the 2 functions. e.g.: Running the ...
user avatar
  • 33
8 votes
3 answers
638 views

Function in Python to extract web Data

I developed this feature that I think can be improved quite a bit. The result is the desired one, but it took me many lines of code. Any idea to optimize it? ...
user avatar
  • 215
2 votes
3 answers
49 views

regex check variable amount of digits

Check for Expiry Expiry can go from 1 to 299 Expiry can be 1 digit, 2 digits or 3 digits This will be the Input I check my regExp against. ...
user avatar

1
2 3 4 5
18