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
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

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.

3
votes
1answer
16 views

Processing file inclusion directives using mutual recursion

I am preprocessing a set of files where one file is included in another file with an include tag like shown below: file A ...
4
votes
3answers
84 views

Regex match comments and quotes

UPDATE New regex - covers escaped slashes and uses lazy qualifiers: ...
8
votes
2answers
96 views

Convert human readable string to TimeSpan

I want to pass time interval as a string (to program args) and then I want to parse it to TimeSpan. I created simple class: ...
1
vote
2answers
55 views

Find the smallest distance between any two given words in a string

The task: Find an efficient algorithm to find the smallest distance (measured in number of words) between any two given words in a string. For example, given words "hello", and "world" and a ...
5
votes
1answer
60 views

Indenting and dedenting ASP Classic code with Python

I've created a Python script that tries to properly indent and dedent ASP code. Similar to http://www.aspindent.com/ Since I've began using it I've noticed some edge cases that I hadn't anticipated. ...
4
votes
1answer
110 views

Swedish 'Personnummer' validator

I have a small C# program that validates Swedish social security numbers ('Personnummer'). I chose to use Regex as there are many different ways it can be input. ...
-2
votes
2answers
40 views

c# Fastest way to get values from string [closed]

I have a C# app that receives the following commands, via tcp sockets. { key = "foo", value = 1.6557, } I'm currently using this method to get the key-value ...
6
votes
3answers
406 views

Elegant way to replace substring in a regex with optional groups in Python?

Given a string taken from the following set: strings = [ "The sky is blue and I like it", "The tree is green and I love it", "A lemon is yellow" ] I ...
0
votes
2answers
46 views

Select a specific line after matching a pattern

I just recently started using AWK and I'm still learning about it. I have solved the problem I'm about to show but I feel it's not the best solution and I'm trying to find a solution to fit within an ...
5
votes
2answers
88 views

Parsing pairs of a number or number range

I need to process an array of number pairs. Here are the constraints on the pairs: The second item may be missing, in this case 0 will be used as second item - - 38...
5
votes
1answer
491 views

Extracting numeric values from a string containing key:value pairs

I am writing function numericValues(text: String): List[Int] to extract patterns """([a-z]+)\s*:\s*(\d+)""" and return the list ...
-2
votes
2answers
101 views

Sanitizing name strings using PHP

Functionality: This method removes a list of specific terms (e.g., LLC, INC, Inc, Company, etc.) from a list of public companies names. It is part of a class that can be viewed in this link. I'd ...
0
votes
1answer
40 views

Convert natural input into Python executable function

I have been developing a graphical calculator, and to allow for natural user input I have written a function which converts their input into a python readable form. This is my first time using regex, ...
5
votes
1answer
48 views

sed to fix a messy nginx.conf

I have a few servers to fix that repeatedly get their nginx.conf file messed up due to a rogue deploy script. These are the three sed commands I'm using to fix at present: ...
2
votes
1answer
47 views

Form validation function for React

I need to validate multiple input fields using React. I am using a simple if-else block for each input field but I would like to optimize my code and make it better. I feel there can be a better way ...
2
votes
1answer
43 views

Adding prefixes to headers in markdown

I'm adding prefixes to headers in markdown using a script. For example, if I have: # Hello ## World ### Let's add ## Some headers ### Yay! # Foo ## Bar I ...
3
votes
0answers
31 views

Generate CSV from multiple files on Regex Python Output

I have written a python script using regex to extrapolate a poorly formatted text file data table into an actual data table. I am currently printing the output using . C:\my file location\file.csv in ...
4
votes
1answer
189 views

Regex to find variants of “Google”

From the HackerRank question definition: The word google can be spelled in many different ways. E.g. google, g00gle, g0oGle, g<>0gl3, googl3, GooGIe etc... Because g = G o = ...
3
votes
2answers
92 views

Regex Generator in C++

So I am writing an XML parser, and I'm using regexes to do some pattern matching during parsing. However, writing longer regexes quickly became a bit boring, annoying and just confusing. So I thought ...
3
votes
0answers
112 views

Given an input string and a pattern, implement wildcard pattern matching

I have been trying to solve "Wildcard Matching" on leetcode. I know there are more "manual" ways to solve this without using the RE library. But I would like to know if passing the time limit is ...
0
votes
1answer
51 views

C# HTTP proxy performance

I'm implementing HTTP traffic monitor (proxy) for my project right now. It's performance is satisfactory. I've updated regex settings and improved performance but I think there are also ways to make ...
3
votes
2answers
86 views

Removing commented dead code without removing the legitimate comments

This question is the real question asked on StackOverflow. I'm here to review my answer and see how can I optimize it. Here is the answer text: This is a basic approach, but it proposes a proof of ...
2
votes
1answer
62 views

Looping through file finding sequences

For an assignment, I had to loop through a text file, and report any positions that a user entered sequence was found. Is there any way I can make this code more efficient, because it seems like I'm ...
5
votes
1answer
37 views

Regex character class range generator with certain characters excluded

While I was working on a personal project, I found I needed to exclude certain characters in a regex range. So I thought, why not implement a custom range exclusion check for greater efficiency, it'll ...
3
votes
2answers
103 views

Go grep command clone

I am trying to make a simple clone of the command line utility grep. I'm working on it just for fun and to practice Go. The thing is, I am trying to make it in a way that if several files are given at ...
4
votes
1answer
51 views

Converting Markdown to HTML using Go

I recently ported a blog of mine from Python to Go (to improve speed and performance) and while all is great so far, I'd like some help optimising the Markdown ...
3
votes
1answer
97 views

Processing a large list of strings

I am working on an application in C# WPF which reads a large file containing a number of HL7 formatted reports. My application takes in the file, reads and extracts any lines that starts with OBX and ...
1
vote
1answer
75 views

Multiple string replacement (with similarity) using a dictionary [closed]

I'm trying to replace a number of keywords with other corresponding values. I started with this method: ...
4
votes
2answers
76 views

Sanitize file or folder names to work with a legacy system

I'm in the unfortunate position to where I have to create files and folders programmatically that have to work with a legacy system. In this process, the file and folder names have to be heavily ...
5
votes
1answer
71 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 ...
0
votes
1answer
53 views

Custom indexOf for strings javascript with regex

I was wondering how efficient my code is creating custom indexOf for strings in JavaScript using regex instead of looping with a for statement the whole way in most ...
2
votes
1answer
44 views

Counting lower vs non-lowercase tokens for tokenized text with several conditions

Assuming that the text is tokenized with whitespace for a natural language processing task, the goal is to check the count of the words (regardless of casing) and check them through some conditions. ...
-1
votes
1answer
51 views

R Regex : Need only numeric figures [closed]

I'm working on R and using regex to keep only numeric figures in a column (I need to keep digits, negative and decimal sign). Suppose I've a value ...
5
votes
1answer
159 views

Strong Password Detection

I did the following Excercise from Automate the boring stuff with Python Chapter 7: Write a function that uses regular exppressions to make sure the password string it is passed is strong. A ...
6
votes
3answers
468 views

Compute count of unique words using ES6 sets

I have written a function which counts how many unique words are included in a given text. The source-code: ...
3
votes
2answers
67 views

Searching repositories for files with forbidden strings

I wrote a small tool for searching git repositories for forbidden strings that I don't want to commit publicly. It's still something basic but it does the job. The project contains three files. <...
9
votes
1answer
86 views

Minimal regex engine

A few months back, I posted a state machine for review. Thanks to the feedback, I was able to greatly simplify the implementation. I am posting the revised version, together with the Regex class which ...
1
vote
1answer
53 views

Replace characters using multiple dependent regular expression substitutions

I've written the following Python module to iterate over field values in the following two fields: "NAME_LABEL", "CATEGORY". I'm using regular expressions in the following function: "...
2
votes
1answer
50 views

Check values in datatables, with validation rules that vary according to the data source

Background I receive dataframes from several sources (below I call these sources s1, s2 and ...
0
votes
1answer
89 views

IsValidEmailAddress

I have created this function for Delphi 10.1 Berlin to validate an email address entered by the user: ...
2
votes
2answers
122 views

Validate Email as User is typing (JavaScript)

I have the following javascript function validateEmail(value). The goal of the function is to validate the users inputted email as they are typing. So if someone puts nfg@*gmail.com the email will be ...
10
votes
3answers
2k views

Imgur URL parser

Fairly new to Python, and I have been doing a few Edabit challenges, to better help with my problem-solving. I have just completed a some what semi-difficult challenge, and I was hoping for some feed ...
5
votes
1answer
719 views

Find the minimum number of characters to add to make password strong

This is the criteria: Its length is at least 6. It contains at least one digit. It contains at least one lowercase English character. It contains at least one uppercase English character. It contains ...
-1
votes
1answer
101 views

Decoding a string encoded by Caesar Cipher and some delimiters [closed]

I have the following code which I seek to optimize. The result of the bruteforce I already have but I'm just trying to learn some more python using the same example. The code in the data needs to be ...
-1
votes
1answer
259 views

Java Pattern search with variable string in pattern [closed]

Is there any better and compact way to write this code: ...
-1
votes
1answer
589 views

changing root password with an ansible playbook

It is with great difficulty that I resolved to solve my problem, so I allow myself to submit here the solution. I wanted a playbook that could replace on all hosts the root password with a string ...
7
votes
2answers
2k views

Find files by pattern and copy to target location

This is my solution to the Chapter 9 exercise in Automate the Boring Stuff: Selective Copy Write a program that walks through a folder tree and searches for files with a certain file extension ...
7
votes
3answers
553 views

Method for returning valid URLs from a sitemap URL

I need a method which fetches all of the text from a URL (generally a sitemap URL), and returns an IEnumerable of all valid URLs contained in the text returned from ...