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.

learn more… | top users | synonyms

1
vote
2answers
54 views

Sum all numbers in text using regexp

I would like to improve everything that can be improved. I don't understand regex a lot and what could be wrong. The main improve that I am looking for is related with errors. I want make the code ...
3
votes
1answer
22 views

Webpack loader for Phaser.io asset files

The following is a webpack loader for Phaser asset files. The way this is supposed to work is that it looks at the json string, and finds all of values with "url" keys in the json object, and ...
0
votes
1answer
32 views

Regex for mobile number validation

In my country (South Africa) mobile numbers have 10 digits and always start with a "0" (e.g. 0821231231). But they can also have the international dialing code ("+27") replacing the "0" (e.g. ...
4
votes
2answers
65 views

Terminal Chat Room

Summary I have written a pair of Perl scripts that form a UDP chat room allowing users to send messages over the internet with RSA encryption, making the messages imune to MITM attacks. The scripts ...
4
votes
2answers
109 views

Regex for matching expression that consists of single digit numbers and operators

I would like to create a regex that will validate that a string is an equation made up of a single digits and either the * or + ...
2
votes
1answer
30 views

Regular expression matching with string slice in Go

I have a slice of strings, and within each string contains multiple key=value formatted messages. I want to pull all the keys out of the strings so I can collect ...
5
votes
3answers
364 views

Parsing a complex number using regular expressions

Requirements were to create a constructor for a complex number, that receives a string. For example: \$3+5i\$. The regex extracts positive or negative numbers from the string with optional decimal. ...
1
vote
1answer
38 views

Finding a substring within a string using regular expressions

I'm new to Java and is trying to find a substring within a string using regular Expressions. I was just wondering if there are any alternative ways to achieve the same goal, or in a more elegant or ...
2
votes
1answer
30 views

Wikipedia indexer and shortest link finder

I have the following code, how can I make it more efficient? Also, it doesn't always find the shortest route. (See Cat -> Tree) ...
2
votes
3answers
121 views

Adding minutes to a time value in Ruby

I recently submitted a code-challenge for an interview according to the following guidelines: About Write a function or method that accepts two mandatory arguments and returns a result. ...
1
vote
1answer
46 views

Creating a RegExp in JavaScript from user input

My goal is to accept user input regex in the following forms /regex|here/i /regex|here/ ...
1
vote
2answers
52 views

Regex to match strings safely

The following regex is meant to improve stringmatching by sanitizing the user -defined commandPrefix and checking for whitespace and line-endings after the ...
3
votes
2answers
74 views

Parsing HTML from multiple webpages simultaneously

My friend wrote a scraper in Go that takes the results from a house listing webpage and finds listings for houses that he's interested in. The initial search returns listings, they are filtered by ...
6
votes
2answers
85 views

Parsing option symbols

I think I have this working, but I'm not sure it's completely accurate. I'm trying to parse Option Symbols. An Option Symbol is made up of 4 parts: Root Symbol (up to 6 characters) Expiration Date ...
7
votes
1answer
64 views

RFC 4180-compliant CSV parser in Java

While looking at a recent question, I realized that there is no CSV parser in the standard Java library. I decided to write one that complies with RFC 4180. Highlights of the standard include: ...
2
votes
1answer
62 views

Convert #hashtagstylephrases to a proper list of words

I'm writing a program to split the words contained in an hashtag. For example I want to split the hashtags: #Whatthehello #goback into: ...
2
votes
2answers
80 views

Regex to first match, then replace found matches

In my C# program I am using Regular expressions to: Loop through a list of possible words in need of replacing. For each word, to find out if a string I am given has any matches. If it does, I ...
4
votes
1answer
66 views

Syntax highlighter for HTML and PHP

I've created a JavaScript application to highlight the syntax of HTML and PHP. I know a lot of syntax highlighter are available nowadays, I just created to extend my knowledge in JS and regular ...
9
votes
1answer
70 views

Highlight specific words in a sentence with diacritrics

I am searching for some improvements, particularly in the regex, in the way I highlight specific words in a string. I have keywords into my database stored without any diacritrics The user comes ...
2
votes
1answer
49 views

Truncating article text

I need to show article's content based on this logic: if article's content has to be truncated (e.g for preview) if there's [read more] substring in the content ...
6
votes
1answer
63 views

C# Regex to extract bug ID from Bugzilla JSON response

I have written a series of Regex.Replace() lines to take an input like {"id":36} and convert it to ...
3
votes
2answers
167 views

Multiple regex matches to correct OCR output

Using OCR, my program reads the current selection for each of these categories: format, invert color? and ...
4
votes
1answer
43 views

UK postcode validation and format correction tool

I've been working on a regex-based UK postcode validation and format correction tool - with the aim of creating a list of postcodes that can be readily geocoded. The variety of postcode formats is ...
4
votes
1answer
144 views

Simple lexical analysis - basic calculator

I recently found an interesting series that describes the specifics of how interpreters and compilers work, explaining each step (with code) and encouraging the reader to do exercises. My code is ...
3
votes
2answers
47 views

Multiple regex replacements

I receive a string with a lot of characters that I don't need and I am trying to remove them and replace them with characters that I am able to work with. My current structure has me redefining the ...
8
votes
2answers
117 views

Number to Roman numerals

I've been working on numerals conversion lately. Now the JavaScript course I'm following asked me to do something similar for Roman numerals. To keep things fresh and given the amount of test-cases ...
5
votes
1answer
56 views

Read through a log file to find “Fail” lines

Please bear with me, I'm only about a week into Python. This code is something that I wanted to do once I completed the chapters dealing with opening and reading files, and RegEx. I always feel like ...
3
votes
1answer
75 views

RFC 2812 message validation regex

In my ongoing quest for an IRC client, I'm working on more stringent validation per RFC 2812. As with everything else I'm doing on this project, I'm trying to implement it all from scratch for the ...
3
votes
2answers
210 views

Parsing “mailto:”

Can you help me to review my "mailto:"-parsing function ? Since I'm trying to write less code, that is as simple as possible. I'm not sure there if there is some bug or better solution. ...
2
votes
1answer
74 views

PHP class for reading DTD

A very long time ago, I started development of a code generator for HTML. And some time ago I rewrote it and published it under LGPL v3.0 on Sourceforge.net. It is very universal because one of its ...
6
votes
2answers
131 views

Cancel those hung print jobs

I've created a program that will list all hung print jobs on a specified server, from there it will load them and strip the jobs down to their Job ID then cancel ...
1
vote
1answer
28 views

Convert a string into an R vector expression

Problem: Given a arbitrary string, split by a given regex and format into an R vector expression. E.g. Convert "a..,b..,c,d" into 'c("a","b","c","d")', when the given regex is "[.,]+". Solution in ...
4
votes
3answers
68 views

Replacing multiple search strings simultaneously

A utility method StringUtils.replace to replace multiple search strings simultaneously. I'm looking for a review of any and all aspects, but especially: Is ...
15
votes
2answers
309 views

Count the occurence of nucleobases in DNA string

Inspired by this meta question I decided to take a look at Rosalind. Their first challenge seemed easy enough: An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', ...
9
votes
1answer
172 views

Multi-dimensional array sort and filter functions

As I said in my last post Multi-dimensional ascending and descending sort array function, I'm back with the final version of the code. Added features: Filter array function by following parameters: ...
8
votes
1answer
96 views

Address filter with PHP using regex

I developed a PHP function to get a not formatted address and split it in a street name and number. Following are some patterns of received addresses StreetName Number SrtreetName, Number Number ...
9
votes
2answers
56 views

Find missing web-pages

You are writing your web-page and relentlessly adding links, as you think that links are the best thing a web-page can offer. The fact is that you write links even to pages that do not exist just ...
11
votes
2answers
56 views

What a crooked way to compute the next straight string (advent of code 11)

This year I have been participating in the Advent of Code series of challenges, and it just so happened that I'd be doing them in Javascript. Not my usual weapon of choice, but I do have some ...
4
votes
1answer
164 views

Solution to part 1 of Day 7 Advent of Code in Scala

Does someone want to review my solution to part 1 of Day 7 Advent of Code in Scala? The assignment is here: http://adventofcode.com/day/7 Without repeating the whole text, in short: Given a text file ...
9
votes
1answer
106 views

Tokenize s-expressions in Rust

I'm writing an s-expression tokenizer in Rust. I have the following code written, but it is not idiomatic Rust - it is quite ugly. TokenizerI is simply an ...
4
votes
1answer
40 views

MongoDB - Find records in one collection that match string in 2nd collection

I have a MongoDB collection of product IDs/unique products attributes and a second collection of codes that relate to attributes common for products whose IDs are prefixed with those codes. For ...
12
votes
2answers
103 views

Re-arranging an obfuscated address

I'm getting address (physical address, not digital) input that's obfuscated, and looks like the following: The plaintext version: ...
6
votes
5answers
172 views

Regex password strength test

I've been following a Python programming book and reached the Regex chapter where I encountered this challenge: Write a password strength checker that checks if a password is: At least 8 ...
8
votes
2answers
87 views

Port of NLTK tokenizing code from Python to Rust

I'm working on a port of NLTK to Rust. I am fairly new to Rust, so I wanted to post a small file to check if I was writing idiomatic Rust. I've included the original Python. The Python has docstrings ...
26
votes
2answers
2k views

It'th wabbit theathon

I don't know regex. I want to learn regex, but learning regex just for the sake of regex would be quite boring. So I decided to learn Ruby as well (which so far looks a lot like Python, which I'm ...
2
votes
3answers
74 views

Replacing the second word of some matching lines in a file

I have a file that at some point contains a line of the following form: OutputFilename output.root I want to write a Python function that replaces the text after ...
3
votes
2answers
63 views

PatternMatcher class

I thought of writing a utility class where I can implement patterns that are useful for day-to-day parsing of strings, without having to to import java.util.regex ...
1
vote
1answer
54 views

Variable length string validation against whitelisted characters

I need to validate a variable length string against some white-listed characters. The algorithm that I have works but I have a sneaking suspicion that there is a more elegant solution. The code below ...
5
votes
3answers
68 views

UrlRouter which uses regular expressions to find out what to do

I have created UrlRouter. It should call appropriate controllers methods with extracted values as a parameters. It works fine, but my boss told me that I should ...
2
votes
2answers
328 views

Convert string to spinal case

Due to an excercise, I've made a function that converts given string to spinal case just-like-this-one (all lower case). I did it with two regular expressions. Can ...