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.
4
votes
1answer
17 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
19 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
46 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 ...
13
votes
2answers
273 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', ...
-4
votes
0answers
73 views
Multi-dimensional array sort and filter functions [duplicate]
Here you can find an independent class module containing useful array functions.
Features:
Quick Sort Array Function (ascending and descending)
Filter Array Function by following parameters: ...
9
votes
1answer
153 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
72 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
52 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
47 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
140 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
60 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
33 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
99 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
122 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
71 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
57 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
59 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
39 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
65 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
128 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
58 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
76 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
51 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
35 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
173 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 ...
2
votes
3answers
80 views
Shorter cleaner technique of writing code with variables and lists?
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
79 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
16 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
96 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
176 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
220 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
84 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
34 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
70 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
80 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 ...
0
votes
1answer
59 views
Yet Another Regex-Based MarkDown to HTML converter
I wrote a simple script to translate (a subset of) StackExchange markdown to HTML. I used Regex for this task, but luckily I only had to use simple patterns.
...
1
vote
2answers
50 views
Clean regex matches with named matches
I have a regex pattern that will match some elements from a string and give them a particular name. For example, #^(?<foo>.*)^# will match the whole string ...
-1
votes
1answer
39 views
Extracting Power and Energy out of a slow regex
My WinForms application is a bit slow, I'd like to make it faster. It extracts only the power and energy values out of a string in textBox3, and displays the ...
7
votes
2answers
115 views
Get Wikimedia attributions for images
We are using images from Wikimedia commons for some of Cardshifter's game artwork. I selected some art for each card to make a .jpg file to use in the game clients, ...
4
votes
2answers
84 views
Function that shortens a String based on a term/abbreviation mapping with special cases
This is a update of this question since the requirements for this task changed.
I have a function that takes a description as a String and returns a shortened ...
21
votes
4answers
3k views
“ONCE”, “UPON”, “A”, “TIME”
I'm working on a small program to perform various tasks on text content, primarily at the word level. I wrote these methods as ways to help prepare the raw text file into something more malleable, ...
5
votes
2answers
42 views
Regex for finding After Effects files in scene code format
I haven't used regex a lot and I needed to set up a script that can gather a list of file paths that should adhere to a strict formatting convention, so I thought that sounded like a good opportunity ...
-9
votes
3answers
210 views
Regular expression to match all binary strings with even number of ones and zeros [closed]
POSIX version:
^((00)*|(11)*|((10|01)(\2|\3)*(10|01))*)++$
Emacs version:
...
10
votes
3answers
489 views
Fastest possible text template for repeated use?
While reviewing Sending templatized e-mail to a million contacts, I wrote this implementation to illustrate an alternate approach. It is designed to be the fastest possible way to generate templated ...
2
votes
2answers
68 views
URL pattern matching
The whole process mainly depends on the ProcessFile() function:
I get all the credentials and details from a JSON file.
Initially I get data from the db: two IDs ...
4
votes
3answers
130 views
Class for interpretation of capturing groups inside regex
I wrote a class, which intends to work with regular expression (as a String or Pattern object) to get capturing groups of given ...
1
vote
1answer
22 views
Print first element of the last line of files when the second element does not match a pattern
I am relatively new to Bash, regular expression and stuff.
In a directory, I need to read the last line of all the files that contain the word "fitness", and list (on one line and separated with ...
4
votes
1answer
92 views
IE compatibility mode detection
This method is written for much larger Web application, but I just extracted it and added class and main method around it so that it can be debugged locally.
Browser detection is done in another ...