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
3
votes
1answer
98 views

Return a substring containing a certain pattern to VBA

I've written in a C++ dll the following function to return to VBA a substring containing a certain pattern, given an input string, which contains that substring: ...
2
votes
1answer
1k views

Read/Write a TXT file with timestamp [closed]

I have write this code that read a txt file and re-write it whith the timestamp sorted. This is the result (top image is input, bottom is output) MY QUESTION IS: Anyone do you have a suggestion to ...
1
vote
1answer
138 views

Serve folder content using PHP route (SSI) (dynamic includes)

I have just written a PHP router, but I have some security concerns about this function. I am trying to serve all the content of a folder using this function. I am trying to prevent harmful URLs. <...
4
votes
1answer
81 views

Try every option for a command and make anagrams out of the successful ones

What I have: I am trying to find what words you can make out of Linux command options like ls -cat or ps -elf. To do that I am ...
3
votes
2answers
820 views

Compress svg files in PHP

I wrote something to "compress" svg files. The svg files I am using often have comments and empty <g> tags, and I want to remove them. My main goal is not the ...
3
votes
2answers
87 views

Get a number from a class of a HTML element

I've got an element with multiple classes in a page and I need to dynamically get the number at the end of a specific class name. Example: ...
2
votes
2answers
3k views

Console application to search for files that contain a match for a regex

I created a small console application to recursively search a folder and all subfolders for files that contain a match for a regex. The command line arguments are the path you're looking to search ...
1
vote
2answers
108 views

Display random facts about cities

This is one of the first scripts I've written. I set it aside for a month or so and I'm not sure how to go about refactoring it. I'd love to have it be more OOD, but I have much more studying before ...
6
votes
1answer
917 views

Helper functions to perform simple token replacements in a string

This script provides function T9r, which has some methods to detect, parse and replace tokens "{{ some_token }}" in a string with properties on an object. My use case, to have "composable" json ...
3
votes
1answer
401 views

regular expression for telephone/mobile per country and variable naming

would like to know if there is a better approach in doing a telephone/mobile number regular expression for specific country. this includes naming variables like how to know if format is international ...
1
vote
0answers
1k views

Javascript email and phone validation regex

I'd like to get a review on 2 regexes, one for email and one for phone validation. ...
4
votes
1answer
5k views

Regex to check IP address in Java

I'm toying with Regexes to parse IP Addresses. I've got it to test for anything over 255: ...
-1
votes
1answer
537 views

Javascript to PHP email validation? [closed]

So I'm working on an application where Javascript will first validate the email using a regex and then once sent to PHP, PHP will verify the user did not modify any of the javascript and validate the ...
4
votes
2answers
963 views

Matching a time interval using regex

What I needed to do was check whether a given string matches a certain pattern. The pattern is this: 00:00:00,000 --> 00:00:00,000 Things to keep in mind: ...
2
votes
1answer
58 views

Parsing HTML to download e-books

I'm currently writing a little tool to get into Go. As I'm not familiar with the language I'm especially looking for Conventional go stuff. utility.go feels wrong.Should I wrap the client and email/...
3
votes
2answers
331 views

Extract title with regex

I'm quite new to Go and I feel like this code could be smaller and cleaner. I would love any suggestions and/or hints about mistakes and conventional go things! ...
0
votes
2answers
2k views

Matching whitespace and non-whitespace characters with RegEx

I just started watching some regex tutorials on Plural Sight just to learn how to write a proper regex expression. So far so good, it's been alright and I decided to test my knowledge on Hackerrank. ...
4
votes
1answer
272 views

PHP Regex Input Sanitization

This helper class is supposed to validate the user input from a text based wifi login form. The entire process is basically this: I use the create_voucher ...
2
votes
1answer
409 views

Replace fixed width values over 530px with 100% using RegEx

Our site sends users transactional html emails. That content is then stored in a DB for retrieval when the user visits the mailbox section of our site. The emails which get sent contain media queries ...
2
votes
2answers
295 views

Filtering a data structure using regex predicates

Assume we have a data-structure like this: ...
3
votes
1answer
178 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
2k views

Beginner code for MadLibs game

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

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 ...
5
votes
2answers
82 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 <...
9
votes
2answers
803 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
2answers
2k 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 ...
5
votes
1answer
81 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 ...
8
votes
1answer
3k 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
72 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 ...
2
votes
1answer
529 views

regex string extension

I wrote some string-extensions: ...
1
vote
0answers
1k 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. ...
4
votes
3answers
3k 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 ...
3
votes
2answers
581 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? <...
13
votes
3answers
20k 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 ...
0
votes
1answer
1k views

Slow RegEx to parse from log file

I have the following lines to parse from a log file with 8000 lines which takes about 5 minutes to parse: ...
3
votes
1answer
6k 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
2k 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 ...
10
votes
1answer
373 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
170 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
161 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
456 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
890 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 ...
4
votes
1answer
81 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
437 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
8k 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 ...
32
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
110 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
948 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 ...
2
votes
3answers
3k 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 ...
4
votes
2answers
437 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. ...

1
5 6
7
8 9
17