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
2answers
78 views

Cleaning HTMLs to extract text

I have written the following routine to clean an html raw code and extract the text. It works, but the code is not very well written. Any ideas how to solve this faster and with fewer lines of code? ...
3
votes
1answer
57 views

Regex for nginx log parser

I made the following regular expression for parsing ngnix log ...
0
votes
0answers
33 views

Script for matching regex matches between two lists

gist of this project is that I have two datasets, 1. dfCore, which contains station_code and station_name 2. dfMetrix, which contains station_name the ...
0
votes
3answers
179 views

Check browser compatibility for RequestAnimationFrame and Vanilla JavaScript .animate() API

I'm trying to set up some code to first test if the Vanilla JavaScript .animate() API is Supported, then if it's not check if ...
6
votes
2answers
456 views

FQDN Validation

I'm new to programming, I'd like you to check my work and criticize the hell out of me. What would you do differently? FQDN: https://en.m.wikipedia.org/wiki/Fully_qualified_domain_name 253 ...
3
votes
3answers
95 views

Java regex and replaceAll to extract strings into objects

I have this method that creates book objects. I pass a list of strings (size 60000+) that contain the information of the book, the function then goes and extracts the information makes the book object ...
4
votes
1answer
60 views

Simplifying Regex Expression: calendar

I want to parse a date string with the following general format: Weekday, DD-Mon-YYYY HH:MM:SS. The calendar should also accept: a date without the weekday spaces instead of dashes case-insensitive ...
1
vote
0answers
26 views

Extracting English-French cognates from a messy .txt glossary

After using an online tool to convert a PDF glossary of English-French cognates to a .txt file, I wanted to write a simple script to extract the cognate pairs and save them to a CSV. I could then ...
1
vote
1answer
60 views

Match a multi line text block

I want to count the occurrences of a multi line ASCII pattern within a file. The pattern looks like this: a1 b2 c3 The file I want to search looks like this: (...
3
votes
2answers
68 views

Find and replace consecutive string values in a list

Suppose I have a list that holds a list of column names: ...
2
votes
1answer
121 views

Converting HashMap data to a Response object

I have a HashMap and I want to convert data in it to a Response object. Is it possible to achieve this code that parses the string in a better and optimized and cleaner way, maybe by using streams? <...
2
votes
0answers
30 views

c++ regex helpers

I've created 2 helpers for std::regex. The first helper match fills the given ...
3
votes
0answers
55 views

Powershell: does a file name contain a value

I need to check if a filename contains a value that I get from 2 excel Columns (ContractNumber & PONumber). My Script is too slow right now. It has been running for 1 hour, and it completed only 2%...
2
votes
1answer
40 views

Replace anchor tags and force create new tag with custom attributes

I'm just use the add_filter('the_content', function($content){}); for filtering anchor tags in a post. Basically, I want filter anchor tags to appropriate format. ...
2
votes
1answer
201 views

Strong Password Checker (Python)

Problem Write a program to return True, if a string is a strong password. A password is considered strong if below conditions are all met: It should have at ...
2
votes
1answer
72 views

LeetCode 65: Valid Number (C++)

Problem Validate if a given string can be interpreted as a decimal or scientific number. Examples: ...
4
votes
3answers
699 views

LeetCode 65: Valid Number (Python)

Problem Validate if a given string can be interpreted as a decimal or scientific number. Some examples: ...
5
votes
2answers
134 views

Splitting each word using longest substring that matches in a vocab/dictionary

This function takes in a string and a fixed list of vocab: splits a string into words by spaces for each word, check in the dictionary/vocab and find the longest matching substrings, if none matching ...
4
votes
1answer
137 views

Chuck Norris Joke Teller

I've created a command line joke teller which makes Chuck Norris jokes after communicating with the Chuck Norris API. It also allows you to generate a random person by communicating to the names API ...
3
votes
1answer
202 views

Word frequency analysis: Python

I wrote a very rudimentary code that counts sentences and words in the arbitrary text. Code: ...
2
votes
0answers
79 views

Sanitize input for a “robot on a grid” kata

I have the following piece of code which is FSI tested and works. However, I want to trim it as much as possible (not only the comments, which are there for my own future reference) and make it as ...
2
votes
2answers
78 views

Manipulate urls with regular expressions instead of the slip approach

Basically I have an url which looks like this structurally speaking: http://www.my-site.com/topic1/topic2/topic3/topic4/topic5 and I want to do 2 things to it: <...
3
votes
1answer
122 views

Validate URL with Regex and java.net.URL

I'm writing a URL validator. Firstly, it checks for special characters in the input. Secondly, it adds 'http://' and checks for validity. ...
5
votes
1answer
57 views

Extract, filter and match three letters from the given arguments and predict the name

Case 1: rank1_naming This function takes two arguments list_proteins_pattern_available best_match_protein_name Objective: Extract the three letter pattern from the both arguments. Match the ...
1
vote
1answer
175 views

Swift: extract string with regex and range

In Swift, I have a string like this http://mnc-hdqp.oss-cn-shanghai.aliyuncs.com/user%2Fheat%2Fdefault.jpg?Signature=2BI%2BauSvy&Expires=1568682491&OSSAccessKeyId=LTAIQ8Lif1HHVkXd Need to ...
2
votes
1answer
51 views

Function to convert “path” into regular expression

This function converts a string like: /{?lang(2-5):lowercase}/{page(2+):lowercase}/{article}-{id:integer}*.html* Into the following regular expression: ...
7
votes
4answers
380 views

Sort files in a given folders and provide as a list

I have two folders query and subject. The following function sorts alphabetically and provides the query and subject as a separate list. The file names are mixed of numbers and I found the sort ...
3
votes
1answer
55 views

Run an external program and extract a pattern match along with the result file

The script takes two input files of protein sequences and runs an external program (installed in linux/MacOS). The result provides a text output file example output.. Identity percentage is extracted ...
1
vote
2answers
66 views

Extract three letter pattern from a given list

The code takes a list of names and extracts the three letter pattern from the names. Then return the list of names as a value in the dictionary with key as a pattern. The list name has a fixed naming ...
6
votes
1answer
70 views

Extract strings from nested array in Perl

Extract the strings from nested arrays in Perl. It prints: a, b, c, d, E ...
6
votes
5answers
270 views

Simple tokenizer v2 - reading all matching chars at once

I have rewritten my tokenizer according to most of the suggestions from the previous question here. API It now reads all chars as long as they match the pattern. I use three types of attributes to ...
4
votes
1answer
201 views

Regex XML validator

I have written a Regex to validate XML/HTML, along with any attributes. It aims to: Match any XML-like text Not match any unclosed tags Adapt for any spacing, newlines, etc. Be as generous as ...
4
votes
1answer
67 views

Sorting email address according to occurrences of each domain

My code: ...
1
vote
1answer
80 views

Script to transpose chords in a song sheet

I'd like to write a script that receives text input from the clipboard that will be from a song lyric sheet with chords. The goal is for the function to return the text to the clipboard after ...
0
votes
1answer
176 views

Extract HTML tags and its content from a string [closed]

Goal I want to extract HTML tags and its content from a string. The content (input) is queried from WordPress database. Sample data (input) I extract this dummy data from my WordPress database: ...
1
vote
1answer
83 views

Format the output of Color.ToString() to RGB values [closed]

The method that I wrote below functions properly; however, I believe that the code I wrote is not clean nor "good". I know the basics of regex but I do not know more advanced techniques as I am still ...
0
votes
0answers
46 views

How to filter URL from the array list based on the string name with regExp?

The solution found to filtering pathname with customising current normalizeTme() function. For sure it is not the ideal way of ...
2
votes
1answer
44 views

HTTP scraper efficiency with multiprocessing

I built this scraper for work that will take a csv list of firewalls from our network management system and scan a given list of HTTPS ports to see if the firewalls are accepting web requests on the ...
1
vote
1answer
45 views

Short function to remove unnecessary whitespace

I have a function consisting of one line of code: def trimString(string): """ Remove unnecessary whitespace. """ return re.sub('\s+', ' ', string).strip() ...
13
votes
0answers
316 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
3answers
2k views

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

At the moment I have this: ...
1
vote
0answers
32 views

git status parser using regular expressions in javascript

I'm looking for improvements of a code that filter the output of git status --ignored and git status --ignored -bs commands. I ...
3
votes
2answers
80 views

Checking the strength of a password using regexes

I'm a beginner in Python and I made a password checker. I'm following these rules: I have to use regex password must be at least 8 characters must have at least one lower case character must have at ...
2
votes
1answer
200 views

Beautifulsoup and lxml (xpath) too slow with respect to regex when parsing HTML

I agree that using regex to parse HTML is not a good way, in particular I am worried about their fragility with respect to change in the HTML. The problem is that any alternatives are really too slow....
0
votes
2answers
1k views

A regex pattern that matches all forms of integers and decimal numbers in Python

The question is pretty self-explanatory. I wrote a regex pattern which should (in theory) match all possible integers and decimal numbers. The pattern is as follows: ...
2
votes
1answer
167 views

Checking if an object meets certain criteria to amend to certain Entity Objects?

I am trying to check if a class has only numeric values in it and then return a bool, however, some instances there may be non numeric chars in an object that ...
6
votes
2answers
443 views

Regex Version of strip()

This problem is from Automate The Boring Stuff using Python - Chapter 7. Write a function that takes a string and does the same thing as the strip() string method. If no other arguments are ...
7
votes
3answers
284 views

Find website URLs that begin with http:// or https://

This is a problem from Automate the Boring Stuff from "Pattern Matching with Regular Expression". I am a beginner in Python and the purpose of this program is to match urls which start with ...
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 ...
0
votes
0answers
31 views

WordPress hook to add URL-rewriting rules for articles with language variants

Please look at this working WordPress code: ...

1
2 3 4 5
16