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 [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.

-4
votes
0answers
21 views

Regex pattern for Any integer between -20 and 100 including -20 and 100.Numeric 3 chars max and no decimal places [on hold]

Can anyone please confirm if the below regex will work for this condition ...
2
votes
2answers
219 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 ...
2
votes
2answers
47 views

Minimizing a file path

I have a simple program that "minimizes" a file path. Minimizing simply means replacing unnecessary file entries with entries that mean the same thing: ...
3
votes
2answers
68 views

RegEx version control

this is my first time on this stack exchange :) I created a little script to check for the latest version of specified API version available, but I am wondering if I am using the best way possible ...
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: ...
15
votes
2answers
493 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 ...
9
votes
2answers
779 views

Count line of code for a JavaScript project

Here is my bash script that I just wrote to count line of code for JavaScript project. It will list number of: Comment lines Blank lines All lines Here is my script: ...
3
votes
0answers
48 views

PL/pgSQL function to test if a word is contained within a phrase

I am using PostgreSQL 11.0 and I wrote a PL/pgSQL function to test if a word or phrase is contained within another phrase. This function is called several times within another function to extract some ...
2
votes
2answers
113 views

Python program to get the first word

Given a string the task it to find its first word with some rules: The string can have points and commas A word can start with a letter, a point or space One word can contain one apostrophe and it ...
4
votes
1answer
41 views

Find filenames with 4 digits which are not divisible by 20 and delete them

I have a set of files in folder my_dir, which is not the folder where my Python script resides. Sample content of my_dir: ...
2
votes
1answer
57 views

Unique Email Addresses

The task was taken from leetcode Every email consists of a local name and a domain name, separated by the @ sign. For example, in alice@leetcode.com, alice is the local name, and leetcode....
8
votes
1answer
833 views

Regular Expression Evaluator

Task to be accomplished: Write a function that takes two strings s and p as arguments and returns a boolean denoting whether s matches p. p is a sequence of any number of the following: a-z - ...
1
vote
1answer
45 views

Convert query string into object in JavaScript

Suppose I have this query and want to convert into an object a1.b2.article1=0&a2.article2=1&c3!article3=0&article16-abc=2 output for this should be ...
5
votes
1answer
35 views

Analyzing a web access log to obtaining totals for requests

This program takes the filename as the input and outputs to a file the number of requests that were more than 1000 bytes and the total bytes. Log file example: ...
3
votes
0answers
46 views

Python log entry search utility

I wrote a small utility for searching our web app log files for certain strings. The idea is that if the search string is found somewhere in the entry, the entire entry should be printed. The ...
4
votes
1answer
34 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 ...
5
votes
3answers
106 views

Regex match comments and quotes

UPDATE New regex - covers escaped slashes and uses lazy qualifiers: ...
8
votes
3answers
141 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
62 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
61 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
135 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
52 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
455 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
48 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
92 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
513 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 ...
-1
votes
2answers
115 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
42 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
64 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
54 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
44 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
32 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
197 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
93 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
174 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 ...
1
vote
1answer
54 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
88 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
69 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
39 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
186 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
55 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
110 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
96 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
93 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 ...
4
votes
1answer
78 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
57 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
46 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
52 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 ...