The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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

Method for returning valid URLs from a sitemap URL

I need a method which fetches all of the text from a URL (generally a sitemap URL), and returns an IEnumerable of all valid URLs contained in the text returned from ...
6
votes
2answers
247 views

Finite state automata

This is a non-deterministic finite state automata (NFA) meant to be used with a Regex engine. To show some example usage, suppose you wanted to construct an NFA for the regex ...
4
votes
1answer
57 views

Enforcing numeric inputs and sanitizing different formats for IE11 input fields

I'm working on a web form that functions with numeric inputs. I have <input type="number"> input fields and with Chrome and Firefox things work nicely since ...
1
vote
1answer
75 views

Java Regex for Chess notations

I have this regex: (\d?)[A-Za-z](?=(\d?)(.*))(?=(.* ){5}) It would be used by me for Chess FEN strings. I wonder if regex ...
3
votes
1answer
85 views

Regular Expression for text that validates IPV4 or Hostname followed by a port number eg: 127.0.0.1:8080 or localhost:8080

An attempt with regular expression to do a foolproof validation of an IV4 or Hostname:port Number. Example texts that can be validated for any of the following: ...
3
votes
3answers
127 views

Reading a file line by line - Two tokens per entry

Problem Read a file and capture two tokens for every multi-line entry. First token is hexcode with which the entry starts. Second token is the remaining line(multi-line) of the entry. Trailing ...
1
vote
1answer
31 views

Rewriting domain only if not on local dev enviroment and forcing www with Mod Rewrite

I'm trying to write some mod rewrite code to redirect pages on a site to always use www and this has been working fine: ...
13
votes
5answers
4k views

Cleaning up date strings in Python

Working from a CSV of about 14.000 lines, I need to match dates in the CSV against some API. I'm reading the CSV using Pandas (for various other reasons). Most often, the date is just a year, i.e. an ...
2
votes
1answer
29 views

Finding incorrect yml headers

Introduction I am working on a semi large project with a few hundred files. In this project there is a series of lesson.yml files I want to check is formatted correctly. And, yes, every file I want ...
4
votes
2answers
102 views

Scan files and pick overlapped hex codes

Problem Two folders having files with nameEfile that store lines starting with hex codes. Print those hex codes that overlap in both folders. Solution ...
2
votes
2answers
57 views

Kotlin program to summarize git commits by regex match

I am trying to learn Kotlin. I am coming from some background in Java. As a learning exercise, I wrote this simple program to summarize occurrences of a string by author email in a list of git ...
4
votes
2answers
78 views

Assigning several variables from request URL using regexes

I refactored some of my code: Summary: This implementation works with PSGI/Plack. It gets the URL from $env->{PATH_INFO} and assigns a different variable ...
1
vote
2answers
78 views

Powershell function to search CSV logs for certain regexes

I have a parser that goes through two different logs, both .csv files, and checks for certain lines based off the regex code that I have chosen. This parser works fine, it just takes about a minute ...
1
vote
0answers
65 views

Determining if a regex can be found in a string

I've written my first C++ multithreaded application (as far as I can recall) which determines if a regex can be found in a string. This code works correct to the best of my knowledge. Could you gals/...
5
votes
2answers
80 views

Regex-based parsing of a specifier for dice

In this android app, the user can enter (a subset of) roll20 notation to roll that many dice. Inputs will look like "4d6" at the simplest, but the user can also add or subtract numbers, and drop or ...
2
votes
0answers
548 views

Regex search to Excel

I made this to track my variable changes while I experiment in Python. I tend to use the same variable names and fit different values to them so it's nice to be able to see what I've tried, especially ...
3
votes
3answers
180 views

Retrieve words from dictionary when they meet letter requirements

I have a set of functions that retrieve words from some arbitrary dictionary based on what letters they have. For example, this function gets words that use only the specified letters: ...
3
votes
1answer
29 views

Ruby Regex to update various variables inside a file

In our applications we have a version file that has three variables that are then joined to create a string that can be used for the semantic version. The file looks like: ...
5
votes
2answers
460 views

Searching for a word in a list of tuple extracted from a db via SQL

Python 3.6 and Sqlite3. I have a database with something like 300K entries, each entry has several fields (date, username, etc) and a "text" one. I have a list of 200 words and for each word i have ...
5
votes
2answers
764 views

Simple parser with regular expression

If I draw something in Illustrator and extract it with AI2Canvas I want it to be customizable so I wrote this simple program. It adds two variables: one to resize and one to shift the path coordinate. ...
4
votes
1answer
83 views

Attempt at Perl transliteration function in JavaScript with flags

I've been trying to rewrite the perl transliteration function in javascript. This isn't a complete replication, and I haven't looked at the perl source code... I took inspiration from this question ...
1
vote
1answer
84 views

UserScript to Highlight tab for queue item

It may seem a bit obsessive and/or pedantic, but the following script allows me to see when posts are ready for reviewing. I developed this UserScript for use with TamperMonkey to allow me to have a ...
3
votes
1answer
530 views

Regular expression to parse guid and other attributes

I have this regular expression that extracts guid and couple of other attributes like name, type and version. Please review the regex for any optimizations and improvements. Strings are always in the ...
2
votes
2answers
95 views

Sorting a JavaScript array with a Regex

I'm using SharePoint 2013 JSOM. My variable this.templates contains a collection of templates with many different names. The only way to iterate through this ...
-2
votes
2answers
707 views

Extracting parameters from request URL path components using regexes

The code is not efficient, let's say the url matched in the first regex case but I'm still evaluating second regex for the second case while knowing it's mutually exclusive and only one of them will ...
2
votes
1answer
117 views

Counting different kinds of line terminator characters in files

Can someone take a look if this code piece is ok. I'm most interested whether the goroutines are used correctly, but also general Go best practices. ...
12
votes
2answers
4k views

Parsing an email string

My program needs to parse an e-mail string. There are two possibilities to enter an e-mail-address. Either with the alias or without one, plain the e-mail-address. 1st possibity: ...
2
votes
0answers
32 views

dyon vim syntax plugin

I recently made vim-dyon which is a syntax highlighter and indenter for the dyon programming language. There are probably some issues with being absolutely correct (since I am not too familiar with ...
2
votes
1answer
589 views

Pig Latin game resolved with a regex in Java

I recreated the Pig Latin game on Java. The program takes an arbitrary number of command line arguments as words, and prints to the standard output these words translated with following rules: For ...
9
votes
2answers
158 views

Payments and liabilities

Get names from names.txt Get transactions from transactions.txt The output of the program should show who owes what like so: ...
5
votes
1answer
655 views

Python: wild card pattern matching with memoization

Here is my take on wild card pattern matching with memoization. I would appreciate comments on clarity of the code, as well as suggested ways to improve readability and maintainability (for bigger ...
4
votes
1answer
84 views

GNU Make variable relationship graph using Python

This program runs through a preprocessed makefile (make --print-data-base | python make_graph.py [options]) to assemble a directed graph of its variables. I ...
3
votes
1answer
108 views

Parser and solver for percentage calculation problems

I'm working on a coding challenge to help with regular expressions, and how to write better comments in my code. The class parses a percentage question, and can return the answer. If anyone has any ...
6
votes
1answer
6k views

Text cleaning script, producing lowercase words with minimal punctuation

I created following script to clean text that I scraped. The clean text would ideally be lowercase words, without numbers and at maybe only commas and a dot at the end of a sentence. It should only ...
0
votes
2answers
4k views

Remove all html special chars

Before saving the input from users in the database, I am using the below function to replace all HTML special chars. All my users will always be using the English Language. Option 1 ...
-3
votes
1answer
38 views

Parse sentences

Task: Parse sentences, even multiline Tests: Hello. I'm dog. to ['Hello.',"I'm dog."] Hello.I'm dog. to ...
2
votes
0answers
36 views

Multilang sentence to N-gram

Task: Transform sentence to n-gram and remove all punctuation Tests: Input: ngram('Name, + other ~ name!', 1) Result: ['Name', 'other', 'name'] Input: ngram('Name, + other ~ name!', 2) ...
4
votes
1answer
357 views

Regex pattern definition implementation

My requirement is to design a part of a solution in such matter that specific placeholders are replaces dynamically with a defined logic and new rules can be easily added. Simple example: Today is ...
2
votes
0answers
222 views

Convert python's strftime directives to user-friendly format examples

I'm converting python's very un user-friendly strftime date time directives to user-friendly formats so that users of an API will know how to format a date if they send an invalid format. My thinking ...
13
votes
1answer
344 views

Voting plugin for an IRC bot

MetaBrainz has an IRC channel called #metabrainz on which there's a bot called BrainzBot running. It provides utilities such as linking to JIRA issues or Github PRs ...
3
votes
2answers
86 views

Safe, simultaneous string replacement

I've written a function which takes as an input: a string to be modified a vector of regular expressions on which to match a vector of replacements option to ignore case in the match statements The ...
1
vote
1answer
474 views

Regex for a string with at least a letter and no repeating dash

I had a problem a few days back and had to find a regex that matches a string that: Contains only letters in the alphabet [a-z0-9-] so lowercase latin letters, ...
1
vote
1answer
2k views

If a regex match is found assign it to a variable

I am searching a string for a pattern that matches Material=. Some examples are Material=ABC123,Color=444555, ...
3
votes
1answer
176 views

Advent of Code 2017, Day 7 - Recursive Circus

This is my solution to Advent of Code 2017, Day 7 – Recursive Circus (both parts, you might not be able to see the second part unless you're logged in and solved the first part, but I'll summarize it ...
2
votes
1answer
63 views

Parsing airline reservation using JS regular expressions

I'm searching a set text for multiple values, which will later be stored in a database. I am using RegExp and worked with the official documentation and help to get the code to be two separate while ...
2
votes
1answer
63 views

MySQL Connection URI Regular Expression

I'm currently working on a project that involves a MySQL database. To make life a little easier, I've been working on a regex that should validate and pull apart the different sections of the ...
4
votes
1answer
124 views

Frame hack to get variable names as strings

I don't claim this is useful nor that it adheres to best practices. There's also no good reason the hack is a context manager, and it won't work on the interactive shell. ...
13
votes
1answer
32k views

Parse complex text files using Python

I'm looking for a simple way of parsing complex text files into a pandas DataFrame. Below is a sample file, what I want the result to look like after parsing, and my current method. Is there any way ...
4
votes
1answer
367 views

A basic Object Orientated REPL Implementation

Here is a very basic object orientated implementation of a read evaluate print loop AKA REPL. I encluded REShell to demonstrate how one could use ...
2
votes
0answers
460 views

Leetcode 10: Regular Expression Matching

Problem statement Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching ...