Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [regular-expressions]

According to Wikipedia, a regular expression (abbreviated regex or regexp) is a sequence of characters that forms a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. "find and replace"-like operations.

0
votes
0answers
26 views

regex for future matching

I am creating dashboard with backend python script which displays data extracted from an email account. Currently, the backend script that parses the various emails operates off of regex matching for ...
1
vote
0answers
64 views

How and why did so many different systems of Regex develop differently? [closed]

In Notepad++ * stands for an arbitrary string and . for one arbitrary character (optionally including newlines). In the Linux console * stands for an arbitrary string and ? for one arbitrary character....
1
vote
1answer
83 views

Is it possible to create a regular language from an non regular language?

I am wondering if it is possible to create a regular language from a irregular language if we add or remove finite number of words from it? say L is irregular, can we add or remove finite number of ...
2
votes
4answers
383 views

What is the optimal way to perform 5000 unique string replace functions in terms of performance?

Restructuring some code, and the way I built it up over time has portions that look something like this: s.replace("ABW"," Aruba "); s.replace("AFG"," Afghanistan "); s.replace("AGO"," Angola "); s....
1
vote
1answer
1k views

Is it a good practice to include empty/white space checks in RegEx?

The goal of the RegEx is to match exactly 6 characters, but in addition it should match empty strings or white space (e.g: ^$|\s|^(\w){6}$). Is it good practice check for empty string/white space in a ...
2
votes
1answer
156 views

Why are `]` and `}` not metacharacters in Regex when ')' is?

In Regular Expressions Quick Start, it reads Twelve characters have special meanings in regular expressions: the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar ...
9
votes
4answers
407 views

Guarding user input of regular expressions against attacks

I am aware of Regular Expression Denial of Service (ReDoS). Is there any reasonable way to allow users to create custom regexes while guaranteeing that they don't submit an exponentially slow pattern?
5
votes
1answer
406 views

How to parse a simple custom syntax in Go?

I have a limited amount of input types: 34:56 = sensorA#, sensorA#, sensorB# 2:5 = { led# } 66 = otherSensor 2,3,4,5 = greenRelay#, redRelay#, relayA#, relayA# a:b implies range. {name} implies a ...
5
votes
2answers
873 views

Is the negation of a regular expression still regular?

All articles (example) I read till now about regular expressions and NFAs explain three operations: sequence alternation (union) repetition (Kleene star) No one talks about negation. Is the ...
10
votes
5answers
707 views

Is placing text markers inside of strings bad style? Is there an alternative?

I work with massive strings which need a lot of manipulation. For example, I might generate a string like this: Part 1 Boat Section A Programming Part 2 Partitioning boats for ...
-2
votes
1answer
558 views

What string will match the regular expression (^$)|(^.*\\{count\\}.*$)\n?

I'm trying to pass a parameter to create a thumbnail in AWS Elastic transcoder, which shouldn't be that difficult except I know nothing about regular expressions. My log is giving me the following ...
3
votes
2answers
3k views

Is it appropite for a tokenizer to use regex to gather tokens?

I have recently caught the 'Toy Language' bug, and have been experimenting with various simple tokenizer configurations. The most recent one, makes use of the boost.regex library to identify and get ...
1
vote
2answers
3k views

Mapping enum values into regexes

I'm doing some code cleanup and I'm looking at my regexes. I have an extremely simple one: (ARA|CHI|FRE|GER|ITA|JPN|RUS|SPA)\s[0-9]{3}-[0-9]{2} It basically validates course identifiers for a ...
7
votes
2answers
242 views

Finding and counting equal substrings in a set of strings

I'm thinking about a way of finding similar parts in Strings. I have a set of strings of varying length i.e: The quick brown fox jumps fox force five the bunny is much quicker than the fox is First, ...
0
votes
1answer
72 views

Is PCRE execution time primitive recursive or recursive?

In other words, is it possible to create a PCRE "regular" expression which takes Ackermann(m,m) time for an m length string?
0
votes
2answers
237 views

How to escape regexes and paths in double quote strings without going crazy?

It often happens that after designing my regexp (on regex101.com) I want to paste it in my program. Consider this regexp that matches numbers and string (but keep in mind this is general question!): ^...
0
votes
1answer
239 views

Why is the “global” RegEx flag in JavaScript considered a property of regular expression itself?

In JavaScript, RegEx objects can be instantiated with flags such as g for global matching and i for case-insensitive. Intuitively, it makes sense for i to be a property of the constructed RegEx, ...
34
votes
6answers
4k views

Should there be unit tests for complex regular expressions?

Should I write unit tests for complex regular expressions in my application? On the one hand: they are easy to test because input and output format is often simple and well-defined, and they can ...
0
votes
1answer
65 views

Creating hyperlinks in documents and messages

In Sweden the abbreviation "t.ex." means "for example" ("till exempel") and it is extremely common. Every time I write that t.ex. in an email or in a text message it gets marked up as a clickable ...
3
votes
1answer
1k views

Guidelines for returning None vs. raising Error for Python string-validating functions

Let's say we have a function that checks if a given pattern occurs in a string. The default behaviour is that if the pattern matches, then it returns the pattern. So far so good but what is the ...
-1
votes
1answer
266 views

Enable matching of character sequence made up of regex control character [closed]

Java Pattern provides flags that enables you match regex control characters. Passing Pattern.LITERAL or 16 as second argument will match any Unicode char, but not if you use a word bound with the ...
-2
votes
2answers
194 views

How to find all occurrences of a variable within a source code?

The title is pretty self-explanatory. I have a minified JavaScript code (100k+ lines) and would like to find all occurrences of a particular variable so I could rename it to better understand code. Is ...
3
votes
1answer
916 views

Is it possible to write a regex that does one search then uses its results to do another search?

I'm searching for strings matching the pattern [A-Z]\W*[0-9]+, so that in V-2345 35A235 Q252 the V-2345 and Q252 would match. In another list, I want to find equivalent items that fit the same ...
1
vote
0answers
46 views

Correlating Search Classifiers in a Database Scan for Sensitive Information

Problem Description I am working on an enterprise data discovery project that is designed to scan databases for sensitive information. The basic search unit is called a classifier and covers things ...
0
votes
1answer
260 views

What would be an actual DFA/actual regex engine solve this simple regex pattern?

.*foo Academically, that is a regular expression. A string aaaaaaaaaaaaafoo will match that. Also string aaaaaaaaaaaaafooaaaaafoo will match that too. I would imagine that an NFA that solve that ...
160
votes
10answers
13k views

Is there a specific reason for the poor readability of regular expression syntax design?

Programmers all seem to agree that readability of code is far more important than short-syntaxed one-liners which work, but require a senior developer to interpret with any degree of accuracy - but ...
2
votes
1answer
141 views

Regex backtracking on simple pattern

I've got this code in Mathematica that fetches the left or right side of an equation by turning it into pure text then textually getting rid of the other side through regex. I've isolated the faulty ...
4
votes
2answers
955 views

why regex, when using global search and {0,} quantifier, match the end of the string?

I have asked a question here about js, regex, quantifiers and global search. I've understood finally how this works, but, let's take a concrete example and then I`ll write my question. Based on the ...
0
votes
1answer
104 views

Is the regex syntax in .net 3.5 the same as the regex syntax in the latest version of .net framework in c#?

Is the regex syntax in .net 3.5 the same as the regex syntax in the latest version of .net framework in c#?
1
vote
1answer
211 views

Matching groups of similar lines on a generic matching algorithm

I have to write a program to search through a file containing lines and find lines that match to a degree of tolerance but are not necessarily the same. So for example the following lines would match: ...
3
votes
1answer
225 views

Features of a routing system

I have been tinkering with the idea of creating a routing system as a learning experience and not for some production purpose. I have trying to decide what features are a must have and what features ...
0
votes
1answer
366 views

How to choose between different ways to write some code?

I would like to validate point in a two-dimensional rectangular Cartesian coordinate. I found following regular expression solution on stackoverflow ^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$ . Another ...
1
vote
0answers
96 views

Simplifying backreferences

This is a theoretical example for simplicity's sake. I use flat values in the regex to make it easily legible for almost anyone, since lots of {,(,[,\'s all jammed together can be a headache to read. ...
1
vote
1answer
477 views

Understanding of concatenation, union and iteration at regular language

I'm trying to understand what a regular language is. There are 3 compound regular expressions for regular language: concat {AB}, union {A+B} and iteration {A*}. When they are used in a simple ways it'...
2
votes
3answers
4k views

Can regexp be used to check for palindromes?

Can regexp pattern matching be used to check for palindromes within a given text in Java? My intuition is that in order to check for palindromes, we may need to remember the character that was parsed,...
1
vote
2answers
203 views

Writing a simple code validator

I know that programming languages can be defined in EBNF which can be converted into regular expressions. Right now I am working on a very simple BASIC interpreter for a project. The code has to be ...
3
votes
1answer
2k views

How to create an algorithm for determining Boolean Tautologies

So i am right now exploring some topics in a proof course and it occurred to me to try to create a boolean tautology solver. I would like an algorithm that is more efficient than brute force. Problem ...
5
votes
2answers
250 views

Need overview of concepts and tools to translate a DSL to regular expressions

I'm looking for a little guidance. Until this morning, this was all over my head. After spending today researching Wikipedia, StackOverflow, etc., I'd say I've got my nose above the water. I'm tasked ...
3
votes
4answers
10k views

Regex to String generation

Let's say that we have a regex and an index i. If we suppose that the set of strings that match our regex are sorted in a lexicographical order, how could we get the i element of this list? Edit : I ...
3
votes
1answer
814 views

Why does the regular expression metacharacter \w include underscores?

In most, if not all implementations of regular expressions, the \w metacharacter matches all alphanumeric characters plus the underscore. Historically speaking, why was the underscore character ...
-2
votes
2answers
780 views

Implementing a basic interpreter - should I learn regular expressions? [closed]

For fun and for practice, I'm thinking of maybe implementing a very basic programming language to run on a simple interpreter written in Java. My question is this: Is it a 'must' to know regular ...
0
votes
2answers
2k views

Word recognition in a string without spaces or punctuation marks

I have a small C# project that reads a file and gives me an output: a string that does not contain spaces nor any types of punctuation marks. It may also contain a few misspellings. Ex. Output: ...
-1
votes
1answer
2k views

What is the right way to parse HTML? [closed]

I've heard, that parsing HTML using the Cthulhu way is not very good. But what are the right ways to parse HTML? Or is it possible to parse it at all?
15
votes
7answers
2k views

Should I refactor large functions that mostly consist of one regex? [closed]

I just wrote a function that spans approximately 100 lines. Hearing that, you are probably tempted to tell me about single responsibilities and urge me to refactor. This is my gut instinct as well, ...
4
votes
2answers
1k views

Regular Expressions and Language Generators

I have few CS textbooks with me which discuss languages, well actually 2 plus old course notes supplied a few years ago. I have been searching the web too any only seem to come up with vague responses ...
3
votes
1answer
536 views

Nomenclature for wildcard vs regex expressions

When I see the term pattern in a description of syntax I infer a regular expression is being specified. Is there a separate term that specifies a wildcard expression? ^foo.*(bar|baz){3} <-- '...
200
votes
17answers
47k views

What is meant by “Now you have two problems”?

There is a popular quote by Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. How is this quote supposed to be ...
0
votes
2answers
2k views

Multi regex matching — what to do to optimize it?

I have multiple regexes matching an input in greedy-first mode. All regexes are already compiled and I don't see what I can do more to speed-up things. I mean using tools coming with .Net framework. ...
4
votes
1answer
1k views

Object oriented parser model review

First time I make use of Code Review. At the moment I'm creating an Android application and the company I'm developing it for, has a specific file format that can be used to give text based data ...
-1
votes
1answer
250 views

Building a regex builder [closed]

I am a beginner in programming in general and web development in particular. I am especially bad at regular expressions. Recently I was involved in building a couple of cPanel plugins(Perl-CGI) and ...