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

SSRS: code function to sanitise HTML for rendering in RDLC report

Background I have an RDLC that among other things displays text coming in that is captured in SharePoint, using a custom control (TinyMCE) that exposes limited formatting options to users. The SSRS ...
1
vote
1answer
35 views

Password validator using regular expressions

I wanted to learn some regex, but learning regex is super boring so I decided to write a password validator that will validate a password with regular expressions. How it works: You enter a ...
5
votes
1answer
29 views

Improving CSV filtering with Python using regex

Consider a .csv file that contains a set of video names like so: ...
8
votes
3answers
881 views

Word-counting script in C#

My goal is to read from standard input, break up the input into words (Unicode letters and apostrophes), case-insensitively, and produce a report to standard output, where each line is a word followed ...
3
votes
0answers
30 views

Convert accented character to user name

I am using below function for converting the accented character to user name. ...
7
votes
0answers
65 views

Parse regular expression

Task: This function searches given null terminated string pStr by given subset of regular expression pMatch. Return value is ...
7
votes
1answer
36 views

Python App that parses file for lines that match a format

I recently wrote some code that was dinged on not having well defined tests and poor modularity. Was hoping someone could review my code and give me pointers on how to create more well-defined tests (...
2
votes
1answer
34 views

Derived Class to keep track of “original strings” in std::regex and ease out their usage while coding

We all know that std::regex class doesn't allow access to the original string which was used as the source expression. (In fact, GCC even keeps the original string as ...
3
votes
2answers
59 views

Optimize a simple and quick python script for transposing a .csv file

I need to transpose the following file output1.csv, which is is a result from a quantum chemistry calculation into a single colum efficiently: ...
6
votes
0answers
29 views

Regex-guided crawler that downloads regex-matching images up to a crawling level

This is one simple crawler that downloads images from websites, the website's URL to be crawled to must match the regex, as well as any image-to-download's URL. (Also, I know, I made my own thread ...
7
votes
3answers
126 views

Test if a string is a palindrome

I got this out of an article on interviews / code challenges. The challenge text goes like this: A palindrome is a word, phrase, number, or other sequence of characters which reads the same ...
5
votes
2answers
67 views

Basic arithmetic calculator in JavaScript

Task is basically: "Write a function which takes two number as the first two parameter. The third parameter is one of the arithmetic operators (+ , - , * , /). Execute the arithmetic operation (...
4
votes
2answers
21 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
67 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)...
2
votes
1answer
56 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
25 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
65 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
48 views
3
votes
1answer
53 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
17 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
38 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
519 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
104 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
39 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
48 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
161 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
45 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
110 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
54 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
90 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
24 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
55 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
44 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
47 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
46 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
124 views
2
votes
4answers
577 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
587 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
72 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
74 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
49 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
62 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
76 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
127 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
93 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
460 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
52 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
38 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) ...