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
0answers
9 views

Notepad ++ (REGEX); Invert Selection, [on hold]

Notepad ++ (REGEX); Invert Selection, The following 2 different codes, it works very nicely. :) now I want to combine these two different code! \bhttps?:[^)''"\s]+.(?:jpg|jpeg|gif|png) Regex to get ...
0
votes
0answers
15 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. ...
3
votes
2answers
50 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 ...
2
votes
0answers
28 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
49 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
10 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
47 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
37 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
40 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
37 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
34 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 ...
-1
votes
0answers
19 views

Guidelines for returning None vs. raising exceptions for Python string-validating functions [migrated]

Let's say we have a function that checks if a given pattern occurs in a string. The default behaviour is that if the pattern matches, then it returns the pattern. So far so good but what is the ...
1
vote
0answers
99 views
2
votes
4answers
523 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
536 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
69 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
60 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
35 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
41 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
72 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
123 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
48 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
386 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
46 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
34 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
130 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
50 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
54 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
92 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
96 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
112 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
75 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
73 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
53 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
85 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
191 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
44 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
151 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
51 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
126 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
63 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
76 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
222 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
75 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
132 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
31 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
71 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
323 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', ...