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.

learn more… | top users | synonyms

0
votes
0answers
8 views

Recursive function implementation in Groovy for repeated execution of formulas

Hi I have the following recursive function written in Groovy but language does not matter. I am just looking for any advice on making it better/faster. Is my approach correct? I think I need recursion ...
1
vote
1answer
30 views

Remove specific CSS rules from WYSIWYG text

I have created a working function for cleaning some specific styles within the text from a WYSIWYG editor. ...
10
votes
1answer
56 views

Beginner code for MadLibs game

I am working through Automate the Boring Stuff. How can I make this code cleaner/better? ...
2
votes
1answer
20 views

R regex, remove all characters except

My code takes a string and replaces all characters which are not: English letters Numbers , / - I have tested it and it seems to generally work well enough. But ...
4
votes
2answers
49 views

Replacing MySQL's AUTO_INCREMENT with Postgres' SERIAL

I am making changes to a Python script that converts MySQL scripts to PostgreSQL, and I want to replace strings such as id INTEGER NOT NULL AUTO_INCREMENT with <...
8
votes
2answers
75 views

Extract unique terms from a PANDAS series

Background I have process tons of DataFrames with shapes of ~230 columns x ~2000-50000+ rows. Here is an extremely simplified example; ...
1
vote
0answers
38 views

Checking that a 6-digit number is not repeated and not in sequence

Following is the objective C code snippet to check that the 6-digit number is not repeated and not in sequence/reverse-sequence. I have just printed the proper messages in ...
4
votes
1answer
64 views

Method to encode ordinary characters into html format

I have had a problem with encoding in a project when trying to convert certain html code into image format. It happens when we receive html that has certain characters with accents and other non ...
7
votes
1answer
67 views

Python hash verification tool

I wanted to better understand regular expressions, however, just learning regular expressions would be extremely boring. So I created a simple little program that will verify a hash by the length and ...
1
vote
1answer
48 views

Checking that a string matches one regex and doesn't match another

I'm using pylint and flake8 to control the code quality. However I am in check-mate position, where styling one does not suit ...
1
vote
1answer
46 views

regex string extension

I wrote some string-extensions: ...
0
votes
0answers
35 views

C# Regex to match UTC dates

Made the following regex strings to match for typical UTC dates. I'd appreciate it if you guys can let me know if it seems fine and not too lengthy. ...
1
vote
1answer
46 views

Confirm regex for validating password policy

I have the following password policy: At least 8 characters in length At least one digit At least one special* character *I consider any character that is not a letter, digit or space to be a ...
2
votes
2answers
61 views

JavaScript Regex Test and Replace

I need to sanitize some chars. I have a solution that works but I am wondering if there is a better solution that may be faster or better or if I flat out should be approaching this differently? <...
5
votes
3answers
190 views

Escape user input for use in JS regex

I am building a highlight feature for search results on my website and need to escape the user's input so that I could highlight the matching string within the original text. The function ...
-1
votes
1answer
43 views

Slow RegEx to parse from log file

I have the following lines to parse from log file with 8,000 lines which takes about 5 minutes: ...
3
votes
1answer
104 views

Extracting JSON from string using regex

I need to get the value of item inside of this string and parse it as JSON. I've got some working code but I feel like it could be optimized (a lot) and cleaned up (a lot). Any tips or pointers are ...
8
votes
2answers
1k views

Python traverse a directory recursively and print contact numbers

I am writing a python code to recursively traverse a directory containing only text files and then print the 10 digit Indian phone number and all its variants. I am very new to python and I have ...
9
votes
1answer
92 views

Adding x86 assembly language syntax highlighting to Google Prettify

Frustrated by the lack of syntax highlighting on Stack Exchange sites for code snippets written in x86 assembly language, I decided to do something about it. The network uses Google Code Prettify as ...
2
votes
0answers
74 views

PHP tagging script

I have created this PHP script in Laravel. I have database table with items and in my app I can create tags with different regexes. If regex matches text in description or epoch. I will insert ...
5
votes
1answer
147 views

Extracting citations of court documents in multiple languages

I've got 20'000+ court documents I want to pull specific data points out of: date, document number, verdict. I am using Python and Regex to perform this. The verdicts are in three languages (German, ...
7
votes
3answers
82 views

Find all needles in the haystack and return their sum

This is based on a programming challenge I recently solved. However, since the writer of the challenge asked me not to disclose the question and/or it's answer, I modified it a little. If it doesn't ...
5
votes
1answer
90 views

Scoring each letter in a word

I've made code that scores each letter in a word you input according to the table below: 1: AEILNORSTU 2: DG 3: BCMP 4: FHVWY 5: K 8: JX 10: QZ I appreciate any feedback, but the ...
3
votes
1answer
54 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 ...
6
votes
2answers
97 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 ...
5
votes
2answers
143 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 ...
25
votes
3answers
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
55 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" ...
11
votes
3answers
525 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
80 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
53 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
29 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: ...
9
votes
1answer
135 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
46 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
57 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
47 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
25 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
99 views

Performing a 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
74 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
62 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
624 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: ...
5
votes
0answers
48 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
117 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
83 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
30 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
100 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
54 views

Replacing mapply to gain speed

I have the following data frame: ...
0
votes
1answer
67 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
98 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 ...