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
1answer
309 views

Classification using a regex tokenizer

This is an updated version of my previous post found here. Mainly as a courtesy for anyone interested. I have Taken most of the advise. Apart from a couple of things. I can't figure out how to use ...
2
votes
0answers
3k views

Regex credit card expiry date auto format

I'm trying to write a function that will get content from input element and try to format numbers entered in input box in MM/YY. Following is a solution that I have, and I want to reduce the number of ...
4
votes
1answer
378 views

Classification of Date/Time/DateTime

I'd like to share a methodology I've been using when faced with a classification problem. This particular example is designed to classify time data as Date/Time/DateTime. Though I believe it could ...
3
votes
0answers
263 views

Scraper Class with Regex

I already posted a not (yet) complete version of this class, but that question got closed, because it contained not passing tests. Here is the full version, all 5 tests pass. Originally there was ...
2
votes
1answer
770 views

Regular Expression Matching: Recursive and DP-based implementation

Problem Statement: Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching ...
2
votes
2answers
97 views

Basic command line REPL calculator

I'm pretty confident in this code but I want to be sure I haven't missed anything to do with optimization or error handling. The program takes input in the form of ...
4
votes
1answer
457 views

Matching a set of conditions based on keywords to text

I am currently working on a function that should return true or false based on a condition written in string by a user. The condition will look something like this: ...
1
vote
0answers
65 views

Systematically reordering parts of street names and replacing abbreviations

I'm working on cleaning up the openstreetmap data, hope to make it more concise. The goal is to change the following street name in two parts: check to see if (S) is at the end of the name If yes, ...
1
vote
1answer
354 views

Validate Louis Vuitton Date Code

On Louis Vuitton bags they contain a "date code" on a tag inside the bag. This code is sometimes used to validate the authenticity of the bag. In reference to this site: http://authenticationfiles....
2
votes
0answers
48 views

Regex to find wildcard imports in Java

Could I get a review on the following regex: ^import[\s\S&&[^\*\n]]*?([\*]{1}\;\s*$) All the details: Years ago a colleague shared a useful little regex ...
2
votes
1answer
479 views

Scraping data unveiling a button from craigslist

I've written some code to parse the names and phone numbers from craigslist. It starts from the link in "m_url" then goes one layer deep to parse the name and then again another layer deep to parse ...
5
votes
1answer
109 views

Selecting site to browse in python

This code is for part of my first major contribution to open-source, for the socli project. The purpose is to allow the user to select a site from the stack exchange network to browse and fill two ...
4
votes
1answer
2k views

Regular Expression to Remove Comments

This was developed in response to a question on Stack Overflow, Removing comments using regex. What the OP needed was a regular expression to use in C# to remove comnents from lines of a file. All ...
3
votes
1answer
790 views

python recursive regex optimization

I parse a big source code directory (100k files). I traverse every line in every file and look for function calls via regex matching. I know that using regex to parse languages is a terrible idea. ...
2
votes
1answer
464 views

JavaScript Website-Content Grabber

I my firm a few people have following problem: A Content Management System is hosted externally. The treaty doesn't include database-access. In September the treaty will expire. So they have to get ...
3
votes
1answer
93 views

Retrieve a number in a webpage and store in a SQLite3 db

I'm beggining Python. So I wrote a program which is supposed to get a number of connected people on a forum (like this one : http://www.jeuxvideo.com/forums/0-51-0-1-0-1-0-blabla-18-25-ans.htm) and ...
5
votes
1answer
182 views

Wrap string at certain delimiters

The method receives an unformatted string and it needs to put line breaks after ';' or before 'i)' and 'i.', where i - integer. If received a string like '; 1)', then it should add only one line ...
3
votes
1answer
365 views

Number of capture groups in a regular expression in php

I am trying to find the number of capture groups for a regular expression using this PHP function. ...
2
votes
1answer
234 views

Regex to DFA parser in Dart

I've created a Regex to DFA parser, using Thompson's construction algorithm and epsilon-reduction. Here is the code: builtins.dart: ...
7
votes
2answers
8k views

Convert Persian and Arabic digits to English

I use the following utility method to convert Persian and Arabic digits to English using regex: ...
1
vote
1answer
123 views

Pattern matching (like regex)

This is a much more basic implementation of Regular Expressions (Python docs). Do note that core functionality is missing and the functions aren't completely fool-proof, but it does a good job of ...
1
vote
0answers
765 views

Finding a repeated pattern and doing something with the match

I have several implementations of finding a repeated pattern and acting on the matching input if it is found. So I want to find this ...
1
vote
0answers
68 views

python indexing-code optimization

I'm writing a plugin to a text editor that will perform indexing of large code bases. The indexer will retrieve all function calls for a certain function (much like the functionality of full featured ...
3
votes
2answers
669 views

Cleaning up an utterance using multiple regex substitutions

I need to use regex for some stuff (mentioned in code comments) and wrote the following code, which works perfectly fine for my need, but I wanted to know if there was a way to improve this code? Am ...
5
votes
2answers
67 views

Convert strings from OW format to ADE format using many regex replacements

I have a working C# (version 5) function that I use to match an input string to one of many unique regular expression patterns and return the replacement string associated with the matched pattern (...
7
votes
1answer
4k views

Basic JavaScript template engine using replace, match and RegExp

To practice with regular expressions, I wrote this basic template engine in JavaScript in addition to a simple test case to make sure it works correctly. I am wondering if there is any improvements I ...
3
votes
2answers
796 views

Parsing very simple CSS into selector and declarations (as as single piece)

The last part of my HTML genrator requries a few styles. Because all styles are inline and the styling is for emails there won't be any fancy selectors, just by element, id or class. The most ...
3
votes
1answer
1k views

Using simple HTML template to create HTML formatting rules

One of my tools that renders HTML needs some rules about document formatting. The renderer can format the output so that it is indented and contains appropriate line-breaks. In the first version I ...
6
votes
1answer
63 views

My second requests script for a wargame

This is a addition to my previous question earlier today. I've taken the suggested changes into account and have written a solution to Natas7, a problem that requires some more 'meat' on what I'd ...
0
votes
1answer
99 views

Converting Confluence markup to a simpler XML format

I have a code that converts one xml structure to another. I am removing unnecessary tags and replacing some temporarily. I think I have way too many replace operations and wondering if there is a way ...
7
votes
4answers
377 views

Count patterns that start and end with “1”, with 0's in between

A string contains many patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0's. The patterns are allowed to overlap. For example, consider string "1101001", we can ...
2
votes
1answer
173 views

Count regex in file

I have a task to search regex in many files. How do you think is this code optimal by performance and complexity? ...
3
votes
1answer
2k views

Parsing and evaluating cron expression

I wasn't happy with my last attempt to parse a cron expression so I simplified it and now I use regex instead. I'd like you to take a look at this solution whether I'm doing something terribly wrong. ...
8
votes
1answer
547 views

A simple regex based lexer

Recently I've been interested in language design and text processing. And a common program needed in both of those fields is a lexer. And since I found myself writing a new, slightly different lexer ...
1
vote
1answer
44 views

Python script to identify regex matches in all subdirs and write dict of matches to MongoDB

I've been attempting to teach myself Python over the past couple of months and have been setting myself practical challenges to learn different aspects of the language. I have a deep structure of ...
5
votes
1answer
270 views

Finding the first non-repeated character in a string

Given a string, find the first non-repeated character in it. E.g. "yellow" should return "y" There are several solutions for this in other languages but I haven't seen one written in Perl. My main ...
7
votes
2answers
4k views

Using python and beautifulsoup to iterate through a list of websites to find a particular string

I'm attempting to find companies who mention a particular service in on their homepage. To do this, I am iterating through a csv file with two columns - ID and URL. I'm using BeautifulSoup to get the ...
16
votes
2answers
592 views

Using lots of regex substitutions to tokenize text

I authored a piece of code that was merged into the nltk codebase. It is full of regex substitutions: ...
2
votes
2answers
95 views

Extracting an IP address from a hosts file by hostname

I am currently working with Vagrant for the first time, and therefore also working with Ruby for the first time. I have a specific hostname and IP address I would like set for my VM, both of which are ...
3
votes
1answer
93 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
842 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
136 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
75 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
1answer
563 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 ...
2
votes
2answers
84 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
2k 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
107 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
538 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
347 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
774 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. ...