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
17 views

Removing comments from code with a program [migrated]

I'm working on a problem that requires me to remove comments from Java code and print out the results. I tried to use regex and came up with this. private static void stripComments(Scanner input) { ...
8
votes
1answer
58 views

Help speeding up my first Bash script

This is my first more-than-1-line script. It takes an inputfolder and a file prefix and get all the files matching. For the first of the files, the script grabs the first line and appends an extra ...
3
votes
2answers
82 views

Parsing annotation

I have implemented code for parsing annotation: /** * @Route(path="sample \n test",code,value,boolean,test) * @access(code=false) * @sample as asdad asd * asd */ function sample() { } ...
7
votes
1answer
57 views

HTTP Authorization header parser

I'm writing a parser for HTTP Authorization header (see RFC2616#14.8 and RFC2617#1.2). Note that I explicitly don't care about the base64-encoded syntax used by HTTP Basic authentication. I'm only ...
2
votes
2answers
72 views

Whitelist HTML tags Microsoft Sanitizer and custom Regex

I have the following code which I have written due to the fact the Microsoft's Sanitizer is now to aggressive. What I'm trying to do is as follows. Create a whitelist of HTML tags I want to keep ...
2
votes
1answer
52 views

Dice notation roller in JavaScript

I have the following function, intended to take standard dice notation (XdY+Z) and return a (sort of) random number based on the input. Are there any bugs/bad ideas/optimizable sections I am missing? ...
9
votes
2answers
209 views

Matching script tags with regexes

Like anything that shouldn't be done, I decided to see if it is possible to match <script> tags robustly using regexes in PHP. Since there is no arbitrary nesting, I figured it should at least ...
4
votes
1answer
88 views

Getting data correctly from <span> tag with beautifulsoup and regex

I am scraping an online shop page and I am trying to get the price mentioned in that page. In the following block, price is mentioned: <span id="hs18Price" itemprop="price" title="New Baby Care ...
5
votes
1answer
78 views

Trying multiple regexes against a single string

I have a huge list of regexes (>1,000 but <1,000,000) that I want to test against (many) single strings. It is unlikely and unintended that more than one such expression would match a single ...
7
votes
5answers
125 views

Reading from text file with RegexMatch

Below is the method that I have written for reading from a text file. While reading, I need to match line string to given regex and if it matches then I need to add the line string to a collection. ...
3
votes
1answer
64 views

Regex to clean text in preparation for word count in PHP

EDIT: Here's my totally-revised PHP... $text = preg_replace("~[^ a-z0-9'-]~"," ",strtolower($INPUT)); for($i=1;$i<strlen($text)-1;$i++) { if(preg_match("~['-]~",$text[$i]) && ( ...
5
votes
1answer
66 views

Calculate query coverage from BLAST output

I have a BLAST output file and want to calculate query coverage, appending the query lengths as an additional column to the output. Let's say I have 2 7 15 f=open('file.txt', 'r') ...
6
votes
2answers
94 views

Recursive Regular Expressions

I want to first search for a specific regular expression. If it is not found then I would like to search for another regular expression If that one is also not found then I would like to search for a ...
0
votes
2answers
121 views

Remove a parameter and its value from URL's query string

I'm coding an algorithm to remove a parameter (let's call it foo) from URL strings. Of course, after the foo parameter removal, the query string should remain valid (with a leading ? and remaining ...
7
votes
1answer
112 views

How could I improve this map-reduce code?

I have been changing this code and I don't get to make it much better, I changed a little bit the structure, reimplemeted a new function for splitting Strings which is more efficient, etc. I have been ...
4
votes
4answers
72 views

Help in deciding how to represent a long regular expression

I wrote a simple Polynomial class: class Polynomial def initialize(coefficients) @coefficients = coefficients.reverse end def to_s return '0' if @coefficients.all?(&:zero?) ...
1
vote
1answer
54 views

TCPDUMP file (part of a real capture)

I have been working on this code for quite a while and just want to make sure it is up to good standards. I know many of you will have questions, so as they come up, I will edit my initial question to ...
3
votes
2answers
75 views

Either or case in Python and Regex

I have a small module that gets the lemma of a word and its plural form. It then searches through sentences looking for a sentence that contains both words (singular or plural) in either order. I have ...
2
votes
3answers
325 views

Convert Sql LIKE to Regex

I have a bit of code that converts a Sql Like expression to a regex expression for the purposes of a Linq to objects Like extension method. For some time I have been using this conversion. This ...
6
votes
3answers
107 views

A regex in Java. Latin letters, digits, dots, and minus signs

There is a user login, and the requirements are the following: The login must start with a Latin letter. The login must finish with either a Latin letter or a digit. There may also be digits, ...
2
votes
1answer
57 views

Finding PHP URL

I've made a Regex to find any URL on site, which uses PHP: Reg = new ...
3
votes
3answers
58 views

Limited typecasting with regex

long time user/lurker at stackoverflow, first time here. I've seen a lot of questions like this have people point to this section of the StackExchange network so I hope this is the right place. I'm ...
4
votes
1answer
133 views

Regex parser - request for review and optimization

The whole question is Better implementation of a simplified regular expression engine?. I have solved the question, and in turn felt the need to get it reviewed. Any suggestions for clean up and ...
0
votes
2answers
81 views

Reducing number of blank spaces

This program takes blank spaces before some chars like > < />, and if there is more than one blank space in the line, it will reduce to one. return source.replaceAll("\\s{2,}", " ...
5
votes
2answers
368 views

What do you think of my regex for URL validation?

I would like you to review my regex. It's suppose to recognize common URLs like: http://www.google.com http://www.sub1.sub2.google.com https://www.google.com http://www.google.com/path1/path2 ...
1
vote
2answers
207 views

Performance: getting first value from comma delimited string

I've got a string that has values that are delimited by comma's, like so: $var = '1,23,45,123,145,200'; I'd like to get just the first value, so what I do is create an array from it and get the ...
2
votes
1answer
167 views

How to replace plain URLs with links, in javascript? [closed]

I've nearly got this working. I wanted to know if there is a much better way. One problem is that no matter what there will be cases where a URL is incorrectly identified and as such the end result ...
3
votes
1answer
92 views

Optimize regex for maximum speed

According to http://stackoverflow.com/questions/19608546/optimize-regex-for-maximum-speed and comments to ask my question here . Please help me to optimize following regex to best performance . I have ...
1
vote
2answers
100 views

How do you “sordid sort” alphanumeric strings?

The question is about sorting alphanumeric string in a "more natural" order. Source: Marc LeBrun's "Sordid Sort" Computist Quiz Often a system string comparison sorts alphanumeric data ...
1
vote
2answers
144 views

Trying to improve my javascript code in this simple challenge from coderbyte

Here is a slightly modified challenge from Coderbyte: Determine if a given string is an acceptable. The str parameter will be composed of + and = symbols with several letters between them (ie. ...
1
vote
2answers
67 views

Checking name E-mail and unit-test

Please tell me what you think. Is my code bad? Function checking #-*- coding: utf-8 -*- import re import unittest def email_check(mail): # E-mail as argument func compil = re.compile(r""" ...
16
votes
4answers
1k views

Regex to parse semicolon-delimited fields is too slow

I have a file with just 3500 lines like these: filecontent= "13P397;Fotostuff;t;IBM;IBM lalala 123|IBM lalala 1234;28.000 things;;IBMlalala123|IBMlalala1234" Then I want to grab every line from the ...
5
votes
1answer
66 views

dir=“auto” JavaScript shim for IE

Reason for script: dir="auto" is an attribute value from the HTML 5 spec with current poor support in IE and Opera browsers ...
2
votes
1answer
92 views

JavaScript HTTP regular expression

I am currently using the following to convert [url=][/url] to an HTML link: s = message.replace(/\[url=([^\]]+)\]\s*(.*?)\s*\[\/url\]/gi, "<a href='$1'>$2</a>") That work's fine. I ...
1
vote
1answer
99 views

wild card pattern matching algorithm

i was trying to write code which does a validation for below wildcards: '?' ------> The question mark indicates there is zero or one of the preceding element. For example, colou?r matches ...
0
votes
1answer
41 views

Cleaner RegEx Syntax

I've got information that is imported from a CSV file that my site grabs every day with PHP. I'm just learning RegEx so I'm able to do what I need to do but am looking to get more efficient with my ...
1
vote
4answers
122 views

How can I shorten and remove repetition from this Python script?

I've got a CSV that contains users and permissions in the below format, where users can have as little as one or as many as eight different permissions: ...
1
vote
2answers
98 views

Optimization of a while-loop searching for words in a dictionary

This is my first question here. I'm using an open source program called MElt which lemmatize (give the lemma example:giving-->give) of words. MElt works on Linux and its programmed in Perl and ...
3
votes
1answer
372 views

Regex to remove inline javascript from string

I need to remove inline javascript for a given string. Examples: If user typed: <img onload="something" /> I should need to convert into <img /> I created this PHP code and it ...
0
votes
1answer
88 views

Avoiding dynamic RegEx creation in JavaScript

This function's job is to replace several text smilies, e.g. :D, :), :love with the appropriate smiley image. In my opinion my code has several issues, yet the main problem is that a lot of quite ...
1
vote
0answers
133 views

Regular Expression Generator [closed]

This library allows you to call functions to describe a regular expression, and then check if a string matches that regex- or replace things in a string based on that regex. I am trying to improve my ...
0
votes
3answers
60 views

Structured instructions for simple extraction script

I have a rather simple task in trying to extract keywords from input.dat which looks like: func1 { yes true; keyword123 (1.1 0 -0.3); gamma (0 1 0); dir ...
3
votes
1answer
232 views

String Interpolation / Word Matching with XML in C#

I'm working on a project where I need to map XML values to field names. Classic CS problem, I think I've got a pretty good approach but would like feedback. For example: breachReportType matches to ...
1
vote
1answer
569 views

string compare, sort, regex split

I am writing a simple code to accept/read a input of lines from a text file, split it into my class variables, sort them and finally display the input in the ordered form. But I am struggling past ...
4
votes
1answer
336 views

Faster code for SVG path parsing? Perhaps improved regex?

I have a module in Python for dealing with SVG paths. One of the problems with this is that the SVG spec is obsessed with saving characters to a pointless extent. As such, this path is valid: ...
3
votes
1answer
823 views

Trim certain characters from a string in javascript

I want to remove not only spaces, but certain characters aswell from the beginning or end of a javascript string. function trim(str, characters) { var c_array = characters.split(''); var ...
2
votes
2answers
156 views

Matching a pattern in many lines of text

This is the relevant piece of my code (false is returned if the whole cycle is finished, pattern is a String passed to the function): for (FileLine fileLine : fileLines) { itemText = ...
1
vote
1answer
60 views

Regular Expression in Javascript to test a string of 1s and 0s

I have a string of four bits which represent true/false values. There are only seven valid options: 1010 1110 0000 1101 1001 1000 0101 There are three options which could potentially be selected ...
2
votes
2answers
157 views

Should I be using Regex to uppercase uncommon characters?

I've written a function for converting strings to upper case. It currently works by replacing each character using a Regex pattern with a hash: # Special upcase function that handles several ...
3
votes
1answer
128 views

Mathematical expression evaluator.

Code reviews and suggestions to improve coding style are welcome. using ExpressionEvaluatorLibrary; namespace ExpressionEvaluator { class Program { static void Main(string[] args) { ...