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
37
votes
4answers
4k views

Someone thinks poorly of my server log parser

I have just been informed that the following code written by me is extremely poor. I have absolutely no idea why. It is memory efficient, and looks clean to me. But still the feedback is very poor. I ...
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 ...
31
votes
10answers
3k views

What are some indicators that I was over-thinking my solution to this problem?

This question is a cross between career question and a code review. I was uncertain where to ask, but since there is code involved I went with CodeReview. I’m going through the process of technical ...
30
votes
3answers
2k views

Regex to parse horizontal rules in Markdown

I'm the current maintainer of Showdownjs, a markdown parser off which PageDown (stackexchange's markdown parser) is based on. Showdown uses the following regex to parse horizontal rules: ...
25
votes
2answers
31k views

Capitalize the first character of all words (even when following a '-')

I got it working, all variations are displayed Sint-Anna as should be, but I wonder, is there a simpler way to this, since it looks very cluttered? ...
24
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, ...
23
votes
5answers
23k views

Use of a regex stored inside a YAML file

I installed settingslogic and in the configuration file I put the regex for the email as follows: ...
21
votes
4answers
8k views

Regex to parse semicolon-delimited fields is too slow

I have a file with just 3500 lines like these: filecontent= "13P397;Fotostuff;t;IBM;IBM lalala 123|IBM lalala 1234;28.000 things;;IBMlalala123|IBMlalala1234" ...
20
votes
2answers
46k views

Email validation using JavaScript

I have a function where I validate emails via a regex. I was wondering if this is the best regex to use or if there's a better way of doing it. Also is there a ...
17
votes
5answers
4k views

Speeding up thousands of string parses

I have a mapping application which takes string arguments in the form of string arrays. I parse these and then perform an action on the map. One of these is ...
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: ...
16
votes
2answers
592 views

Using lots of regex substitutions to tokenize text

I authored a piece of code that was merged into the nltk codebase. It is full of regex substitutions: ...
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 ...
15
votes
2answers
2k views

Markdown to HTML

...
15
votes
2answers
524 views

Convert camelCase and PascalCase to Title Case

I'm trying to take camelCase and PascalCase strings into a function and spit them out as Title Case. This function also needs to be able to handle odd PascalCase strings with capitalized abbreviations ...
15
votes
1answer
50k views

Trim certain characters from a string in JavaScript

I want to remove not only spaces, but certain characters, as well from the beginning or end of a JavaScript string. ...
14
votes
2answers
1k views

Regex Matching a Naming Convention

Program Purpose So, I have a naming convention for certain folders. I want to take in a folder name, and determine if it conforms to the convention. Naming Convention The convention (case ...
14
votes
2answers
439 views

I think I might be having a regex nightmare

I've been working on the Rubberduck (an add-in for the VBA Editor /"VBE"), specifically here the VBA.Parser namespace. Here's how I ended up implementing the syntax ...
14
votes
3answers
180 views

Fighting f̶i̶r̶e̶ regex with f̶i̶r̶e̶ regex

So someone requested a Regex Builder / Assistant for Rubberduck and since my CS class had been covering the topic only recently I was thinking to myself: "This sounds interesting, you should do this". ...
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 ...
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 ...
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 ...
13
votes
2answers
2k views

Average spam confidence

Exercise 7.2 from Python for Informatics: Write a program to prompt for a file name, and then read through the file and look for lines of the form: ...
13
votes
1answer
32k views

Parse complex text files using Python

I'm looking for a simple way of parsing complex text files into a pandas DataFrame. Below is a sample file, what I want the result to look like after parsing, and my current method. Is there any way ...
13
votes
3answers
3k views

Recursive Regular Expressions

I want to first search for a specific regular expression. If it is not found then I would like to search for another regular expression If that one is also not found then I would like to search for a ...
13
votes
1answer
344 views

Voting plugin for an IRC bot

MetaBrainz has an IRC channel called #metabrainz on which there's a bot called BrainzBot running. It provides utilities such as linking to JIRA issues or Github PRs ...
13
votes
1answer
44k views

Getting data correctly from <span> tag with beautifulsoup and regex

I am scraping an online shop page, trying to get the price mentioned in that page. In the following block the price is mentioned: ...
13
votes
1answer
225 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 ...
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 ...
12
votes
4answers
52k views

Simplify splitting a String into alpha and numeric parts

Requirement: Parse a String into chunks of numeric characters and alpha characters. Alpha characters should be separated from the numeric, other characters should be ignored. Example Data: Input ...
12
votes
4answers
2k views

Script for analyzing millions of lines

I have files with over 100 million lines in each: ...
12
votes
2answers
4k views

Parsing an email string

My program needs to parse an e-mail string. There are two possibilities to enter an e-mail-address. Either with the alias or without one, plain the e-mail-address. 1st possibity: ...
12
votes
3answers
11k views

Converting snake_case to PascalCase

Is there an effective way, maybe with regex, to change the following text pattern? I have a string like abc_def_ghi_jkl. I want to replace it to ...
12
votes
2answers
128 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: ...
12
votes
0answers
218 views

“String Interpolation in {language}”, “VBA”

"This is {0} cool!", "freaking" I've always wanted an easy and intuitive way to inject variables into a string. So after about 10 variations, I finally came up with this function. How it works The ...
11
votes
4answers
1k views

What would be preferred aesthetically and performance wise?

Which one of these two would you prefer writing in your code? This: ...
11
votes
3answers
2k views

Convert a string like 4h53m12s to a total number of seconds in JavaScript

At the moment I have this: ...
11
votes
2answers
368 views

Is this a sufficient way to prevent script injections and other bad stuff in strings

Would this function be sufficient enough to remove all malicious code and foreign characters from a string? ...
11
votes
3answers
9k views

Transform snake_case to camelCase

I want to convert db columns such as is_deleted or product_code which consist of xx_xx to ...
11
votes
3answers
897 views

Using Python to tokenize a string in a stack-based programming language

As an avid user of esoteric programming languages, I'm currently designing one, interpreted in Python. The language will be stack-based and scripts will be a mix of symbols, letters, and digits, like ...
11
votes
2answers
5k views

Matching script tags with regexes

Like anything that shouldn't be done, I decided to see if it is possible to match <script> tags robustly using regexes in PHP. Since there is no arbitrary ...
11
votes
3answers
2k 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 ...
11
votes
3answers
7k views

Empty Line delimiter, single line output

I'm used to only processing, at most, one line of a file at a time. This is my first time changing the delimiter, and the objective here is to take a file containing lines such as: ...
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 ...
11
votes
1answer
2k views

A regular expression parsing library in C

I've created a regular expression (regex) parsing library in C, and would like some feedback on it. Speed is really important to me, but any and all suggestions are acceptable. ...
11
votes
2answers
140 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 ...
11
votes
1answer
2k 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 ...
11
votes
1answer
4k views

Convert WKT representations of geometries into GeoJson

I am working on a class library in C# to convert WKT to GeoJson. I am getting shapes in WKT out of MSSQL. A lot of the shapes ...
10
votes
4answers
6k views

Regex to enforce password requirements

I'm trying to write regex to validate the password for the given rule. Passwords must be at least 8 characters in length and contain at least 3 of the following 4 types of characters: lower case ...