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
1
vote
0answers
42 views

Trim real numbers to a set precision when the input is a string

The objective was to allow me to trim a real number to a set precision after the decimal if one exists but only if the value does not contain an exponent. My input is actually a ...
4
votes
1answer
328 views

URL pattern matching for request blocking

I'm trying to write a URL pattern matching utility that, given a pattern and a URL it'll tell whether the URL matches the pattern or not. I want to use this for users to provide a list of URL patterns ...
6
votes
1answer
1k views

Check if there are exactly 3 question marks, in the input string, between the pair of two numbers that add up to 10

I'm just learning about the regular expressions, and found this problem on the internet.It's a nice practice for a beginner in regexp. Problem instruction: Have the function take the string ...
2
votes
1answer
3k views

Faster way of replacing strings in large pandas dataframe with regex

I want to replace all instances of a location with just the location keyword itself, eg "Foxclore Road" with "road", "Chesture Avenue" with "avenue". The file is several GBs, with many million rows. ...
3
votes
1answer
3k views

Identify and extract URLs from text corpus

I'm working on a project that requires POS Tagging of paragraphs. The text contains lot of URLs which contain various punctuation marks such as . ...
4
votes
1answer
68 views

a Python2 to Python3 print fixer in perl

Sometimes, I'm reviewing old questions written in Python2, with no parenthesis around print statements. Or I'm changing one of my older codes, also without ...
5
votes
1answer
108 views

Extract and sort all numbers that appear after ',

I am currently learning Python and I wrote the following code. The code searches the string for all digits that appear after ',, sorts them and joins them into a ...
4
votes
1answer
80 views

Performing substitutions according to a word list in a database

A bit of history I had about 40,000 words in the database. I need words to correct the texts entered incorrectly by users. User enter text in any non-legal format and I use my words in the database ...
7
votes
3answers
2k views

Trimming unicode whitespace, control characters, and line breaks with regex

I'm getting user submitted text from a <textarea></textarea>, and I want to edit it a bit before storing it in a database. Here are my 3 regexes, with ...
4
votes
1answer
167 views

QuickSearch for files and directories

I have a project where I need to search for directories and files. In fact I'm searching for paths in other projects. I don't want to just find files but I also want to exclude some directories or ...
5
votes
2answers
133 views

Better way to extract country wise player list from html file using regex

Problem statement: Make country wise player list from the following html code HTML CODE: ...
3
votes
3answers
185 views

inString() Helper Function - Check if substring is in string

I've written a simple helper function for my helper class that allows me to check if a substring is in a string. With my function, you can supply either a single needle to check for, or an array of ...
4
votes
2answers
313 views

Matching Fasta file header and section of sequence, printing each header only once

I have a Fasta file which I am opening and reading. I need to search for certain regions of the DNA sequence and, for each match found, print the sequence header followed by all matches within that ...
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 ...
1
vote
1answer
222 views

Round a number and replace trailing zeros by spaces

Goal From a number x, I would like a string of the rounded value at n decimals and replace each trailing zeros by a space. ...
2
votes
1answer
63 views

Clean up string and move the noun before the comma

I would like to know how I could improve the regex part of this script? I now chain 4 replace methods which is not optimal. Any ideas of other improvement I'm happy to receive. ...
0
votes
2answers
861 views

Regular expression to identify java function

I am trying to identify a java function block addition in a diff file (new line start with + in diff). For that I am using regular expression. It is working fine, ...
3
votes
2answers
368 views

Recursive right-to-left segmenting (tokenizing) of strings in Python

I want to segment a list of strings based on a custom list of words/forms, from right-to-left. Here I've illustrated it with made-up English examples, but the point is to segment/tokenize using a ...
2
votes
2answers
642 views

Parse a formatted string, which may have duplicate keys, into a map

I have a String which is coming in particular format so I want to parse that string into map. I have a below method which parses String to a Map and it works fine. ...
0
votes
1answer
81 views

Parsing length of work experience using Composite design pattern

I want to get a number from given text (if it exists) which is about work experience in months. I assumed that number is in months when in the text one writes for example "27 miesięcy" or "27 miesiecy"...
6
votes
2answers
496 views

Converting tcpdump output to text2pcap acceptable input

I have some text file in following format (network traffic collected by tcpdump): ...
3
votes
1answer
244 views

Transforming stored procedures using Python regular expressions

I have to add some extra logic to about 80 similar stored procedures on my DWH server. I thought that it would take pretty much the same time if I do it with Python and lots of googling (I have no ...
1
vote
2answers
50 views

Returning lines for a given function from a JavaScript file

The function below iterates through an array that contains all the lines of a JavaScript file (a global array, this_file), and returns just those lines (...
1
vote
1answer
2k views

Mongoose query using conditional formatting and regex

I this the function createQuery is fully functionally, but I would like a review on it. I'm pretty sure this can be shorten and most important (improve performance). Any ideas? ...
2
votes
1answer
953 views

Number to text conversion (Check writing application)

How It Works: Inspired by r/dailyprogrammer, the application uses regular expressions to group 1-3 digits at a time from right to left, each captured group is then converted to text. Program Class <...
5
votes
5answers
161 views

Calculate LIX value of a text

I've been building a simple tool to calculate the LIX value of a text (a standard measurement of the readability of a text). My approach was to have every step of the calculation as seperate ...
3
votes
1answer
101 views

Java parsing and extract String from pattern String

I want to extract some string surrounded by certain patterns. For Instance, the original String something like 1234@{78}dasdh@{1}fdsfs@{fdf}ad@{ and I want extract ...
7
votes
1answer
254 views

Remotely collect server data using Net::OpenSSH Perl

I am newbie in Perl programming and currently trying to use Net::OpenSSH module in my code, my new code as below which the task is to run multiple command in remote server, Code as below:: ...
2
votes
0answers
332 views

C++ regex_replace with arbitrary function

This is a version of C++17 regex_replace that handles arbitrary functions to do the replacement, instead of using regex_replace'...
3
votes
2answers
2k views

User ID & password constraints checker

Please take a look at my code below and tell me if I'm doing the right thing here. My wishes: Username The username must be at least 6 characters long The username can't contain any special symbols ...
2
votes
1answer
70 views

Programming Language Identification in JS

This is a RegExp exercice from HackerRank. Basically, I have to write a program (I chose JavaScript) that receives a program as an input (string) and tries to identify the programming language used. ...
3
votes
2answers
312 views

Is given pattern a subString of given input string? KMP implementation

My implementation of Knuth Morris Pratt algorithm. Looking forward for code review comments. Let me know of there is a better way to implement this algorithm. ...
4
votes
1answer
42 views

Remove every line that include and follows the second occurrence of a given pattern

From a file, I am trying to remove every line that include and follows the second occurrence of a given pattern in Bash (Mac OSX). Note, that a file may have only one match of the given pattern (and ...
3
votes
1answer
147 views

PHP function which filters content from Wordpress database (wp_posts table)

I worked on a hybrid mobile application for a newspaper company. They had a Wordpress website with news content (in a wp_posts table) which they wanted to be displayed in the application. I built the ...
4
votes
2answers
10k views

Extract left text outside the parenthesis if any

Im trying to extract the text on the left, outside the parenthesis (): ...
6
votes
1answer
4k views

Named placeholders filling and extraction in Java

Here's utility class that is capable of filling strings with placeholders and extract values of placeholders from filled strings. Placeholders are enclosed in % ...
8
votes
1answer
541 views

Osherove TDD Kata 1: String Calculator

I implemented Roy Osherove's TDD Kata 1: String Calculator using Python 3.5.2 and the unittest module. The full description can be found at the link, it's a bit ...
2
votes
0answers
56 views

Chromium based browser and Firefox omnibox: paste/type search keywords to go straight to google.com search results

Functions and features: paste/type search keywords to go straight to google.com search results pages - explicitly google.com NO google.TLD ...
5
votes
2answers
64 views

Extracting parts of filenames from an array

I am very new to perl. So far I love it, my new favorite interpreted language. I am quickly learning that perl has MANY 'tricks' to it. The following code extracts file names out of one array and into ...
1
vote
4answers
362 views

Php bad glob pattern

I am getting images using this glob pattern, but the code looks really bad. First I get all images which have the name screenshot + a number from 0-9 in an array, after that I get all screenshort + a ...
5
votes
1answer
1k views

Recursively replace string placeholders with parameterized phrases

I've written a python script to replace certain placeholders in a text with defined phrases. Some of the phrases might contain placeholders themselves, so the script needs to recursively replace them. ...
2
votes
1answer
6k views

Parse through text and extract dates in uniform format

I wrote a script to parse through text and extract all the dates. I would like it to be able to find as many different ways of writing text in dates as possible while containing as few false negatives ...
-1
votes
1answer
1k views

Confirm regex for currency and dollar symbol [closed]

I'm allowing currency, plus letting users enter a dollar symbol (which will be stripped later). So far this seems to work, but I'd like to see if anyone can find an issue with it. Formats Allowed <...
2
votes
1answer
12k views

Regex in Hive QL (RLIKE)

I'm wondering how/if I can improve the regex I'm using in a query. I have a set of identifiers for certain user groups. They can be in two main format: X123 or <...
-3
votes
1answer
5k views

RegEx , match first character condition, then another condition after that? [closed]

I have been struggling with a RegEx pattern for a while now. I am trying to match a single Text character at the start of a ...
2
votes
2answers
173 views

Read file with URLs to connect to them, search for patterns and generate output in multi-threading env

I've been implementing a little application that will read a text file that holds URL addresses (one address per line). Example: ...
7
votes
1answer
196 views

Wrapper to enhance a program to translate from LTL formulae to Büchi automata

The following is a script that is supposed to act as a wrapper for ltl2ba, a program which transforms LTL formulas into Buchi Automatons encoded in the Promela language. The wrapper adds a limited set ...
2
votes
3answers
744 views

Parsing complex string data

I have a complex strings like the following: $company=>Company(code->MyCompany) $brand=>Brand(code->Brand_1, company->$company) and then I prepare ...
-1
votes
2answers
109 views

PHP Regex expression to validate a name input

As part of my validation I have the following regex expression: ...
1
vote
4answers
13k views

Function to remove specified html tags from string

I recently wrote this function that, when supplied a string and an array of element types, will remove those element types from the string. As you could imagine this is a very very simple function, ...