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
1answer
51 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
62 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 ...
0
votes
1answer
32 views

Substring erase with certain pattern

For following input string: ...
2
votes
1answer
44 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
48 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
147 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
39 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
0answers
114 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 ...
2
votes
2answers
43 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
107 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
50 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
73 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
200 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
0answers
64 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
130 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
26 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
64 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
305 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
165 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
83 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
53 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 ...
10
votes
2answers
52 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
154 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
81 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
35 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
101 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
142 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
76 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 ...
27
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
68 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
46 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
66 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
185 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 ...
4
votes
3answers
62 views

'Learn projects the hard way': logfind project

I'm a new programmer, who has just finished his first small project. It's a sort of basic imitation of the grep command from Linux. I'm learning from projects the ...
1
vote
2answers
89 views

Read a txt file and split into 2 csvs based on regex

So I have been told that my code is not good and needs refactoring. I'm struggling to see what I need to do. How do I specify the success and failure conditions for lambda? Also don't get what the ...
4
votes
1answer
61 views

Using Pandas to parse adwords export

I did this exercise yesterday mostly as practice, but it has some utility as well in day to day. I was basically attempting to take a string that looked like the following: ...
3
votes
2answers
36 views

Moving a clock forward

I am taking a Ruby class and our assignment was to write a class that takes two users inputs (1. the time, 2. the amount of minutes to move forward). Then based on the two inputs forward the time by ...
5
votes
2answers
211 views

Counting words from standard input in Swift

I know Swift isn't exactly meant to be used to write your classic stdin to stdout scripts, and that Python, Ruby, Perl, bash, awk, and friends are much better in this area, but I'd still like to see ...
6
votes
3answers
230 views

IP and router connections

How can I make my code more pythonic ? I definitely think there is a way to make this code a lot more readable and clear + shorter... But I haven't found an effective way. Any techniques I can use to ...
3
votes
1answer
81 views

Compile-time wildcard pattern matching

I was in need of a function that could check a string against a certain pattern at compile-time. The pattern can contain any of the commonly known wildcards: ?, * and +. ...
2
votes
1answer
17 views

Optimize a regex validating a version string

I develop an application which installs updates. These updates have a version id (this version id is created as a part of the application and the format is a fixed requirement) and I use a regex to ...
8
votes
1answer
101 views

Find/replace number with commas in Java

I have a requirement to put a comma between each digit of a number in a Java string. Example input: the number is 12345 and the number is 45678 The output ...
2
votes
3answers
179 views

Remove repetitive strings from a given sentence efficiently

I recently gave a test on HackerRank: Given a string, return the most concise string that can be formed from it. For example: ...
6
votes
1answer
225 views

Regular Expression matching customer number strings

Using VB.NET, I have created an AddIn for Autodesk Inventor and the customer has a bunch of drawing number strings which follow this sort of scheme: ...
4
votes
2answers
88 views

A method to capitalize the first letter of all words in a String

I recently was given a task to capitalize the first character of a string provided the string does not begin with a non-alphabet. Below are the requirements and my implementation. Just want to know if ...
2
votes
1answer
45 views

String replacement in OCaml

This is part of my first OCaml program. Its job is to replace a set of placeholder characters with umlauts. Taking the German word Ruebe as an example, the program ...
5
votes
1answer
80 views

Network chat in Perl

I have written a network chat program as my first major project in Perl. It makes simple use of REGEXP's, modules, sockets, command-line option parsing, and forking and uses these features to produce ...
0
votes
1answer
22 views

Check the address String for presence of a New Brunswick abbreviation

I need to check if there are any abbreviation of New Brunswick province in the address. Acceptable abbreviations are: "NB", "N.B.", "N-B", "N.-B." and any combination of upper-lower cases. It ...
2
votes
1answer
85 views

Regular Expression for parsing PHP annotations containing multiple lines and markup

I am writing a regular expression for parsing PHP annotations in a flexible way. I'd like to accomplish all the goals listed above with one single expression. So I would appreciate any suggestions ...