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

4
votes
2answers
15 views

Isolate URLs from other text around it and put each on own line (with sed)

I have a small shell script that uses sed to take an input file of URLs with hand-written notes around them and strips the notes and puts each URL on its own line. ...
1
vote
1answer
56 views

Moving MP3 files from one directory to another using regex

This is a simple script for moving my MP3 files from one directory to another. I'd like to know if there is a more efficient way to handle my task in the script. I analyzed the algorithm to be \$O(n^2)...
1
vote
1answer
43 views

Regex Tool in PHP

I'm looking for feedback about anything and everything to do with this short program. For example, is there a risk in not sanitising the data, and if so, how would I do that given the need for non-...
0
votes
1answer
7 views

Loading a file in vim via piped output of ag

I feel as if my scenario is fairly simple but that I might be overcomplicating it. I am searching through files looking for a special condition, that is where the method ...
1
vote
0answers
22 views

Formatting a CHANGES text file as HTML

I have a function which is used to convert text (a CHANGES file) into HTML for reading. The function is essentially line-based: if the line is of this type, do this thing; if some other type, do that ...
3
votes
2answers
63 views

Validating multiple parameters by regex and length

I have a set of validation functions which return a response code along with an error message if the validation fails. Requests can be of three types, and each of them contains a different type of ...
3
votes
1answer
44 views
3
votes
1answer
52 views

PHP class which preserves line break by splitting the line into as many line break as it have

Can anyone here please review my PHP code which preserves line break by splitting the line into as many line break as it have? ...
0
votes
1answer
16 views

Find the number surrounded by square braces using regex

I need to remove all the numbers appearing inside square braces such as [9] , [2] , .... This is my regex: "(?:\[\d*\])" Which is working fine. But I am totally ...
1
vote
1answer
25 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
325 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 ...
5
votes
2answers
94 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
47 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
146 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
43 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
105 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
11 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
45 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
73 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
19 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
54 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
42 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
46 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
45 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
37 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
117 views
2
votes
4answers
549 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
571 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
71 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. ...
2
votes
2answers
71 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
41 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
58 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
126 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
71 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
441 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
51 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
37 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
137 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
77 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
99 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
118 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
64 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
352 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
80 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
82 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
66 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 ...