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.
1
vote
0answers
8 views
Perl module validate quoted string literal, test with Test::LectroTest
I guess for some motivation: I ripped this out of a larger library I'm half-working on to parse S-expressions and cleaned it up a bit.
I'm trying to write a simple function that tests whether a ...
5
votes
2answers
54 views
Vanilla Markov chain in 18 lines
I am looking for advice on how I can improve this code. The objective is to make a vanilla Markov Chain text generator in the most concise way. I'm looking for advice on style, naming, 'elegance', and ...
-1
votes
0answers
12 views
Scrape Given Site for link (after providing keywords), emails info and link to user [on hold]
Not sure if the for loop covers all parameters, it's flawless on links already on the site.
...
3
votes
2answers
60 views
Using regex to replace strange characters
After importing some products from a csv strange characters have shown up on the page and it would be too much work to manually go to each product and remove them so I made this script to deploy on ...
24
votes
2answers
2k views
Regex to parse horizontal rules in Markdown
I'm the current maintainer of Showdownjs, a markdown parser off which PageDown (stackexchange's markdown parser) is based on.
Showdown uses the following regex to parse horizontal rules:
...
5
votes
1answer
46 views
Regex, match the most informative pattern
I have a function that is designed to parse an utterance (or typed in string) and identify the intent as a yes or no answer.
There are many ways of saying "yes" to something, and similarly for "no" ...
10
votes
3answers
437 views
Using Python to tokenize a string in a stack-based programming language
As an avid user of esoteric programming languages, I'm currently designing one, interpreted in Python.
The language will be stack-based and scripts will be a mix of symbols, letters, and digits, like ...
0
votes
2answers
50 views
Finding all words without a certain character
I am doing some exercises in this book. I've been trying to avoid Regex so far in my mission to teach myself computer science, as it makes my head hurt. That said - one of the exercises is to find all ...
2
votes
1answer
40 views
PHP function to convert a Portuguese word from plural to singular
I know, this sounds really difficult, but it is really easy.
I needed to convert a single Portuguese word in the plural into singular. I know there's a right name for that, but it is escaping me.
...
2
votes
1answer
23 views
Regex detection for Puppet configuration
I've got a PR to add a feature to a Ruby application (Puppet) to allow Regex detection.
Right now, the method only does comparison on exact string matching:
...
6
votes
0answers
74 views
Command Tokenizer
I've written some code to tokenize a command string into its tokens.
A token is either:
A block of any non-whitespace characters
A block of characters, which may include whitespace, wrapped in ...
3
votes
0answers
30 views
Hex Color Analyzer in javafx
Here is a simple hex color fetcher and analyzer in javafx that i wrote to understand multi-threading in javafx.
Questions:
Is my regex ok ? or if it can be improve?
I am not much familiar with ...
1
vote
0answers
52 views
Match the maximum consective count of `)` followed by a keyword
I am applying a regular expression to match and keyword that is followed by maximum number of closing parenthesis. Code is done in python using ...
5
votes
1answer
41 views
Perl script to match case law references
I am very new to Perl and decided to work on a simple script that could solve a problem I encounter in my day to day work. The purpose of the code that follows is to search over a body of text and ...
0
votes
0answers
24 views
Link Detection and Addition of Anchor
I have the following code but I am not too happy about the way I replace e-mails with mailto links. Additionally, I am thinking how to conbine the logic of the URLs and E-mails into one Loop.
...
3
votes
1answer
73 views
Python code to do regex search and saving results to csv
I am a Python beginner, and I wrote a simple Python program, which does the following:
search the pattern in the lines of a file (contains messages)
pick the information from the lines and save it to ...
3
votes
0answers
45 views
Decode HTML Entities in VBA using regex and dictionary
I receive HTML-encoded text that includes named and numbered entities, and I need the decoded HTML.
There were just too many bad solutions for this online.
I use regex pattern ...
-4
votes
2answers
57 views
Given a blob of text (that is a complete html page) return all email(s) present [closed]
Okay so this is NOT my code, I just inherited it. Seems it has an obvious bug that it will only return the first email despite being called "GetEmails". My main concern is actually that it takes ...
5
votes
4answers
604 views
Check if a file path matches any of the patterns in a blacklist
I'm processing a list of files, and want to check the filenames against a list of regex, like:
...
4
votes
0answers
45 views
Counting instances of a string in a binary / unicode file using regex
(Originally posted on Stack Overflow)
I need to run through a number of bespoke files (I'm unsure if they are unicode / ascii or binary so have attached a snapshot through notepad++). I'd like to ...
6
votes
2answers
115 views
Performing a procedure for each form edit
I am a bit new to programming. I have some edits on my form, and for each edit completed it will have to do a procedure.
Currently, I use this code that works perfectly, but I am looking for a better ...
0
votes
1answer
71 views
Extract regex matches with non matching parts
I want to check a string by using multiple search patterns and split the string at every occurrence. I'm using RegEx and it works fine. But I'm worrying about efficiency and performance.
...
1
vote
0answers
25 views
Matching URIs with regexes for Apache CXF InInterceptor
In my project I need to compare the URI with 15+ regex patterns. Currently I have used a if ladder to execute the appropriate code if any of them gets matched.
...
3
votes
0answers
34 views
Formatting XML strings in JavaScript for readability
I've created a vanilla JS function to indent XML strings so they can be more easily read. It uses some pretty nasty regex...yes, I know it's a cardinal sin for XML/HTML, but it works. For instance, ...
3
votes
2answers
28 views
Parsing and extracting all IDs from a document (using regex with capture)
I'm interested in parsing and extracting the IDs found in a document. The IDs are found throughout the document in the this format:
IDStart=1FG3392MQ9&IDEnd
The "1FG3392MQ9" is an example of ...
1
vote
0answers
47 views
0
votes
1answer
62 views
php preg_replace kills cpu
I am reading some HTML files and returning them upon request, but when they go through my codes I need to filter out some stuff from these HTMLs, everything is working fine and I'm using about 20 or ...
4
votes
3answers
91 views
Replacing a string until it matches a certain length
I'm trying to make an SMS Shortner for a kata at Codewars:
Your task is to shorten the message to 160 characters, starting from end, by replacing spaces with camelCase, as much as necessary.
I've ...
2
votes
0answers
60 views
4
votes
1answer
52 views
Average calculator with filters
I am a beginner in Java and I have a hobby project to create a tool for statistical calculations.
Users can upload csv with results of a survey. The responses stored in a ...
3
votes
1answer
105 views
Regex for domain validation name validation
I created this regex in Javascript that returns a boolean for Domain validation that meets the criteria to allow IP addresses and ascii domain name. The assumption is that the TLD should be atleast ...
3
votes
2answers
157 views
Check if a string contains a set of characters
I have written this piece of code to check if a string contains a set of characters, regardless of the order.
Eg: 'ruby is best' / 'bysbe' => true
Code:
...
6
votes
1answer
47 views
Extracting Linux configuration information using Bash and Perl
For few days I'm thinking about making my code faster and using less CPU. This code is a statusbar that runs in a loop. I'm asking because there's a lot of perl and I'm wondering if it could be done ...
2
votes
2answers
56 views
Transform snake_case to camelCase with sed
I want to convert my_long_variable to myLongVariable in sed.
This works:
...
1
vote
2answers
56 views
Phone number/email regex verifier
Is there anything I can do better here? I tried looking for ways to simplify this with comprehension but could not figure out how and was told it is better to explicitly use ...
1
vote
1answer
108 views
Pokemon search engine
I am making a simple function to find and match any possibilities what Pokémon the user wants. This is accomplished by taking in the input (what the user thinks the Pokémon is named) and compare its ...
9
votes
4answers
2k views
Regex to enforce password requirements
I'm trying to write regex to validate the password for the given rule.
Passwords must be at least 8 characters in length and contain at least 3 of the following 4 types of characters:
lower case ...
3
votes
2answers
45 views
Capturing the positions of “start” and “end” markers in a multi-line string
Is there any better (and shorter) way to get index of a regex match in Python?
...
12
votes
2answers
108 views
Fighting f̶i̶r̶e̶ regex with f̶i̶r̶e̶ regex
So someone requested a Regex Builder / Assistant for Rubberduck and since my CS class had been covering the topic only recently I was thinking to myself: "This sounds interesting, you should do this".
...
12
votes
2answers
470 views
Regex Matching a Naming Convention
Program Purpose
So, I have a naming convention for certain folders.
I want to take in a folder name, and determine if it conforms to the convention.
Naming Convention
The convention (case ...
1
vote
0answers
136 views
SSRS: code function to sanitise HTML for rendering in RDLC report
Background
I have an RDLC that among other things displays text coming in that is captured in SharePoint, using a custom control (TinyMCE) that exposes limited formatting options to users.
The SSRS ...
1
vote
1answer
106 views
Password validator using regular expressions
I wanted to learn some regex, but learning regex is super boring so I decided to write a password validator that will validate a password with regular expressions.
How it works:
You enter a password ...
5
votes
1answer
39 views
Improving CSV filtering with Python using regex
Consider a .csv file that contains a set of video names like so:
...
8
votes
3answers
1k views
Word-counting script in C#
My goal is to read from standard input, break up the input into words (Unicode letters and apostrophes), case-insensitively, and produce a report to standard output, where each line is a word followed ...
3
votes
0answers
34 views
Convert accented character to user name
I am using below function for converting the accented character to user name.
...
7
votes
1answer
135 views
Parse regular expression
Task:
This function searches given null terminated string pStr by given subset of
regular expression pMatch.
Return value is ...
7
votes
1answer
44 views
Python App that parses file for lines that match a format
I recently wrote some code that was dinged on not having well defined tests and poor modularity. Was hoping someone could review my code and give me pointers on how to create more well-defined tests (...
2
votes
1answer
38 views
Derived Class to keep track of “original strings” in std::regex and ease out their usage while coding
We all know that std::regex class doesn't allow access to the original string which was used as the source expression. (In fact, GCC even keeps the original string as ...
3
votes
2answers
67 views
Optimize a simple and quick python script for transposing a .csv file
I need to transpose the following file output1.csv, which is is a result from a quantum chemistry calculation into a single colum efficiently:
...
7
votes
0answers
62 views
Regex-guided crawler that downloads regex-matching images up to a crawling level
This is one simple crawler that downloads images from websites, the website's URL to be crawled to must match the regex, as well as any image-to-download's URL.
(Also, I know, I made my own thread ...