The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [regex]

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.

Filter by
Sorted by
Tagged with
13
votes
3answers
5k views

Match Simple Sentence or Partial Sentence

Description Match a Simple Sentence or a partial sentence Suitable for matching People Names (to some extent) Product Titles (to some extent) Correct use of apostrophe (to some extent) Input/Result ...
4
votes
1answer
99 views

Replacing Uri with a more convenient class

I needed some data structure for holding Uris so I thought I try the Uri class. It quickly turned out that it's very impractical because: it's missing an implicit ...
36
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 ...
15
votes
2answers
2k views

Markdown to HTML

...
13
votes
7answers
42k views

Regex validation for Email Address

I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct: Wiki Link Local_part The local-part of the email address may use any of these ASCII ...
17
votes
2answers
443 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', 'G'...
16
votes
2answers
13k views

Faster JavaScript fuzzy string matching function?

I'm using the following function to fuzzy match strings: ...
15
votes
4answers
37k 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 ...
13
votes
5answers
4k views

Cleaning up date strings in Python

Working from a CSV of about 14.000 lines, I need to match dates in the CSV against some API. I'm reading the CSV using Pandas (for various other reasons). Most often, the date is just a year, i.e. an ...
12
votes
3answers
17k views

Escape user input for use in JS regex

I am building a highlight feature for search results on my website and need to escape the user's input so that I could highlight the matching string within the original text. The function ...
6
votes
1answer
540 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 ...
6
votes
5answers
262 views

Simple tokenizer v2 - reading all matching chars at once

I have rewritten my tokenizer according to most of the suggestions from the previous question here. API It now reads all chars as long as they match the pattern. I use three types of attributes to ...
4
votes
3answers
593 views

LeetCode 65: Valid Number (Python)

Problem Validate if a given string can be interpreted as a decimal or scientific number. Some examples: ...
10
votes
2answers
790 views

Generating and calling code on the fly

Delegate This class module defines what I'm calling, in this context, a Delegate - here a function that can take a number of parameters, evaluate a result, and ...
9
votes
1answer
3k 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
4answers
1k 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 ...
6
votes
2answers
247 views

Finite state automata

This is a non-deterministic finite state automata (NFA) meant to be used with a Regex engine. To show some example usage, suppose you wanted to construct an NFA for the regex ...
4
votes
1answer
2k views

JavaScript replace

I am not sure the square brackets are correct (although it has not yet failed some simple tests). I would also like to reduce and simplify this code to one line if practical. I think the code is self ...
3
votes
3answers
120 views

Filter out strings that are short or that are outside the alphabet of a language

I wrote this function to remove from the array those words that are less than n values. More precisely, I updated my old function and added some functionality. Since I am a beginner in this ...
3
votes
1answer
2k views

Parsing and evaluating cron expression

I wasn't happy with my last attempt to parse a cron expression so I simplified it and now I use regex instead. I'd like you to take a look at this solution whether I'm doing something terribly wrong. ...
2
votes
2answers
498 views

Regex version of strip() - Ch. 7 Automate the Boring Stuff

Here is a practice exercise — Regex version of strip() \$-\$ Write a function that takes a string and does the same thing as the ...
11
votes
3answers
4k 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 ...
9
votes
2answers
158 views

Payments and liabilities

Get names from names.txt Get transactions from transactions.txt The output of the program should show who owes what like so: ...
8
votes
2answers
8k views

Finding the largest repeating substring

Here's my code that takes a large string, and searches for the longest reoccurring substring. It compares the first letter with every other until it finds a match, then saves it. Then it compares the ...
7
votes
3answers
870 views

VB6/VBA Declaration (Dim) Syntax Parser

As part of a project I'm working on, I've implemented a class that encapsulates the syntax for a vb6/vba Dim statement. Given a line of code, the ...
6
votes
1answer
96 views

Inserting filename, reading data, inserting regex, and testing if each line matches

This program first displays a menu which shows some options that the user can select. Each option will the respective functions which do some things. The user can insert a filename, read data from it,...
5
votes
2answers
8k views

Simplified regular expression engine

Task: On an alphabet set [a-z], a simplified regular expression is much simpler than the normal regular expression. It has only two meta characters: '.' and '*'. '.' -- exact ...
5
votes
1answer
3k views

Regex parser implementing dot, star and question mark

Regex parser which follows the following rule . (dot) means a any single character match * (star) means 0 or more ...
5
votes
1answer
3k views

Multiplying Lists

Challenge: Given 2 lists of positive integers. Write a program which multiplies corresponding elements in these lists Specifications: Your program should accept as its first argument a path ...
5
votes
1answer
753 views

Regex parser - request for review and optimization

The whole question is Simplified regular expression engine. I have solved the question, and in turn felt the need to get it reviewed. Any suggestions for clean up and optimization would help. Also ...
4
votes
2answers
1k 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 ...
4
votes
1answer
378 views

Classification of Date/Time/DateTime

I'd like to share a methodology I've been using when faced with a classification problem. This particular example is designed to classify time data as Date/Time/DateTime. Though I believe it could ...
4
votes
2answers
7k views

Regex to remove inline javascript from string

I need to remove inline javascript for a given string. Examples: If user typed: <img onload="something" /> I should need to convert into ...
3
votes
4answers
2k views

Product Manager managing product listings and prices

For school we have to develop a product manager. The basic task is to add new products. A product has a name and a price. I know the one or other class is currently pretty empty but its planned to ...
3
votes
1answer
81 views

Inserting filename, reading data, inserting regex, and testing if each line matches - version 2

This is a improved version of the program seen in my older question. This program first displays a menu which shows some options that the user can select. Each option will the respective functions ...
3
votes
1answer
51 views

Run an external program and extract a pattern match along with the result file

The script takes two input files of protein sequences and runs an external program (installed in linux/MacOS). The result provides a text output file example output.. Identity percentage is extracted ...
2
votes
2answers
700 views

Speeding up and fixing phone numbers from CSVs with Regex

I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a ...
2
votes
2answers
994 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
1answer
565 views

TDD: String Calculator Kata

String Calculator Create a simple String calculator with a method int Add(string numbers). The method can take 0, 1 or 2 numbers, and will return ...