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
1answer
18 views

Fraction or percentage regular expression

I'm learning regular expression as part of my Java course. Now I know sometimes the best use of regex is to not use regex at all. But since I have to use it for this course and learn it, I figure I ...
1
vote
3answers
201 views

Calculating the 'binary gap' of a number

Inspired by this question and therefore this one I decided that clearly the best most readable way to solve this is with Regular Expressions. A binary gap within a positive integer N is any ...
4
votes
2answers
81 views

Restrict HTML input field to decimal

I'd like to restrict user input in a form to a decimal with max two numbers before and 4 after decimal point. Valid values would be: 50 0.1 1.23 4.5678 12.943 ...
3
votes
2answers
37 views

Reg expression for finding expression in sentence

I have a regular expression that match the string that contains the word "duration", followed by a < or > operator and ...
1
vote
0answers
44 views

Regex to obtain float values from a large text file

I am reading a text file and obtaining certain data from the file. The following line is repeated over a million times in the file where the £ values may differ each time. Start Game, Credit: ...
2
votes
2answers
133 views

Idiomatic word counting in Rust

My goal is to read from standard input, break up the input into words, case-insensitively, and produce a report to standard output, where each line is a word followed by a space followed by its count. ...
-1
votes
2answers
38 views

Find multiple keyphrases from a text

I have keyphrases abc, xyz, pqr, mno, etc. Text - " this text contains abc and mno", want to find whether text contains keyphrase string. I am looking for an efficient solution. ...
4
votes
4answers
90 views

Advent of Code Day 6: toggling lights in a grid with Powershell

I am using the "Advent of Code" series to help with my PowerShell education. The Day 6 puzzle has a 1000 × 1000 grid of lights. After processing instructions to turn on, turn off, or toggle rectangles ...
1
vote
0answers
9 views

Optimize Advent of Code Day 6 with Powershell [duplicate]

I am using the "Advent of Code" series to help with my Powershell education. http://adventofcode.com/day/6 I am confident that this script will produce the right answer. However, it is going way too ...
2
votes
0answers
36 views

PHP routing system

I made a routing system for PHP inspired by Symfony's router composed of a few classes. First I am using Symfony's HTTP Foundations component. Then, I am emulating the classes in the routing ...
2
votes
2answers
58 views

JavaScript function to convert underscore-case to camel-case (and vice-versa)

Actually I needed a function which converts underscore to camel-case. But then I've had the idea: Why not extend the function so, that is works the other way around? Finally I recalled that there is ...
2
votes
2answers
15 views

Shortest regex search and sum for integers

Given a text file including different text and integer numbers (text.txt), what's the shortest way of getting the sum of all the numbers out if it? I have: ...
1
vote
2answers
50 views

Matching lines in a CSV file with items in a dictionary

I was wondering if there was a better way of writing this... I have a CSV file (about 6640 lines). After reading through the file, the values for the DFN_Network ...
-1
votes
1answer
40 views

Replacing address details in colon delimited string

I'm sanitising personal data in a large database with a series of Regular Expressions. In many cases the sensitive data is in a colon-delimited field within a CSV file. Here is a sample: ...
2
votes
1answer
45 views

Associate an object with a regular expression in Python

Is there a way I can link/associate an object (in this particular case a function) with a regular expression pattern? Here's the function I'm working on: ...
2
votes
1answer
44 views

JavaScript text-analyser to determine how often a defined word appears in text

The idea of my application is to have the user provides text which is pasted (or written) inside the textbook and further provides a search word. The application then shows the overall count of words ...
0
votes
1answer
36 views

Compiler for grond, a language-in-the-making

I'm working on a language called grond (see it on GitHub); the compiler is so small it is included in this post. My gut tells me that this code is awful, but it works. I am hesitant to change things ...
2
votes
1answer
113 views
2
votes
4answers
535 views

regex to extract version info

I have written a small Python function to extract version info from a string. Input is of format: v{Major}.{Minor}[b{beta-num}] Eg: v1.1, v1.10b100, v1.100b01 Goal is to extract Major, Minor and ...
4
votes
3answers
559 views

Eval is evil: Dynamic method calls from named regex groups in Python 3

I'm working on a simple dice roller for a Python IRC bot. The particular game this roller is for uses six different kinds of dice, which I've defined using a simple base class, and created six ...
1
vote
1answer
70 views

JavaScript function which checks the count of words in a string

Task to accomplish: Made a function which counts the amount of words in a sentence. Please don't put attention to the HTML. Is just for testing-purposes. ...
1
vote
2answers
65 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
40 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
50 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
74 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
125 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
59 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
415 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
47 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
36 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
133 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
51 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
56 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
76 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
97 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 ...
8
votes
1answer
111 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
63 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
173 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
77 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
80 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
58 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
103 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
207 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
47 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
158 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
53 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
129 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
66 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
80 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
229 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. ...