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
1answer
58 views
Faster JavaScript fuzzy string matching function?
I'm using the following function to fuzzy match strings:
function fuzzy_match(str,pattern){
pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; });
return (new ...
1
vote
2answers
47 views
php most efficient way to check if a variable contains only certain chars
I have a small function which I regularly use to check if a variable contains only [a-z][0-9] and the special chars '-' and '_'. Currently I'm using the following:
function is_clean($string){
...
1
vote
1answer
18 views
To extract specific information in the stack trace using regular expression
I encountered a problem at http://regexone.com/example/6?
You can view the problem by clicking the link.
There was required a regular expression to extract the method name, filename and the line ...
1
vote
3answers
73 views
How should I read coordinates from a text file?
I have a text file with lines that look like this:
Robot(479.30432416307934|98.90610653676828)
Robot(186.42081184420528|213.11277688981409)
Robot(86.80794277768825|412.1359734884495)
or, more ...
-4
votes
1answer
23 views
Regex to change uri file name [closed]
Looking for regex to change file name in uri to allow linking to answer sheet from question bank.
...
2
votes
1answer
28 views
Encapsulate results in div tags
I would like to turn the following:
<div>this is a $test</div>
into
<div>this is a <div>$test</div></div>
currently I have
var regexp = new ...
1
vote
2answers
36 views
How to make this Regex more flexible?
I am creating a simple template engine that uses Regex to find special expressions, which are parsed and processed. They are enclosed in Ruby-style opening tags and have the format:
<% label ...
0
votes
0answers
41 views
Python pattern searching using re standard lib, str.find()
I'm trying to improve some code in order to get a better perfomance, I have to do a lot of pattern matching for little tags on medium large strings, for example:
import re
STR = ...
1
vote
3answers
156 views
Regex to get all image links - is this efficient?
I have some pretty basic Regex that scans the output of a HTML file (the whole document source) and attempts to extract all of the absolute links that look like images. Whether they are actually ...
3
votes
1answer
172 views
How/where can I improve this code?
I'm quite new to Javascript, what areas of the code should I concentrate on improving, and if possible, how to improve them.
Basically, the code looks for certain emoticon characters (like :) or :|) ...
3
votes
1answer
62 views
Count comments and lines of code in ruby
Hi I wrote a small script as an answer for a stack overflow question, that counts lines of code and comments (in C and C++ style).
f = File.open("test.txt")
loc = 0
comments = 0
while line = f.gets
...
4
votes
2answers
89 views
Refactor highlight matched word in string
I have following method which highlight matched word in text:
# Hightlight matched term
#
# Ex(for term: some):
# "<span class="bold">Some</span> CEO Event"
#
def ...
1
vote
2answers
58 views
Http url validating
What do you think about this?
#utils.py
def is_http_url(s):
"""
Returns true if s is valid http url, else false
Arguments:
- `s`:
"""
if ...
1
vote
1answer
64 views
RegExp selecting strings surrounded by brackets
My purpouse is to select every character which is surrounded by { and }, this is easily achievable using this regexp {\w*}.
I've developed an extenstion method for strings:
public static ...
1
vote
1answer
66 views
Preg_replace improvement
I would like to improve my preg_replace regex.
This is to clean a features list.
I want allow for the begining of each line:
alphanumeric characters
== and alphanumeric characters
-- alphanumeric ...
3
votes
2answers
140 views
Python function to match filenames with extension names
I have written a Python function which matches all files in the current directory with a list of extension names. It is working correctly.
import os, sys, time, re, stat
def matchextname(extnames, ...
0
votes
3answers
95 views
Minimize Number of Lists
I have a string, where I am only interested in getting the numbers encapsulated in single quotes.
For instance if I have the string "hsa456456 ['1', '2', ...]
I only want the 1 and the 2 and ...
2
votes
3answers
264 views
Any suggestions on how to improve this mobile user agent check?
I've been using the following user agent Regular Expression to detect mobile devices, but I recently came across a few resources that listed a whole host of mobile user agents that I had not heard of ...
2
votes
2answers
91 views
Want to sharpen my Python / Regex skills
I have a relatively simple project to parse some http server logs using Python and SQLite. I wrote up the code but I'm always looking for tips on being a better Python scripter. Though this is a ...
1
vote
0answers
77 views
Looking for a good heuristic in C# that will try to detect if the user is trying to search via regex [closed]
I am not sure if this question belongs here or on StackOverflow since my implementation, which compiles and sort of works is not the right solution, because I have not fully decided on what the ...
2
votes
1answer
60 views
Capturing optional regex segment with PHP
I need to check the end of a URL for the possible existence of /news_archive or /news_archive/5 in PHP. The below snippet does exactly what I want, but I know that I could achieve this with one ...
4
votes
1answer
84 views
Is my PHP script/embed remover robust?
The goal of this question:
Your goal here is to find a security hole in my code which allows a user to create input that contains a script doing anything they want, without that script being stopped ...
5
votes
1answer
233 views
Is there anyway to minimize the following code? combine regex for example?
i have built the following code using help from people at stackoverflow,
but i am pretty sure it can be minimized,but since i dont know regex very good (actually hardly), i do not know how to do it.
...
2
votes
2answers
333 views
String pattern matching - method needs improving
I'm trying to build simple pattern matching in a string.
ie., Given a template of: "Hello ${1}" and an input of "Hello world", I'd like to be able to return a map of 1='world'.
This test ...
1
vote
1answer
116 views
Lots of RegEx match against huge number range (PHP)
I have to check a given amount of regular expressions, which are defining number ranges for dial plans, against an input number range.
The target is to check and see, if any of the numbers in the ...
1
vote
1answer
97 views
Perl CGI script to respond to erroneous Base64 image requests
I often get lines like this in my Apache error log:
File does not exist: /path/to/www/data:image/gif;base64,R0lGODlhBgAGAIAOAP/yH5BAEACAEALAAAAAAGGAYAAAIJhB0Xi5vOoFwFADs=
Obviously, this is due to ...
3
votes
1answer
134 views
Implementation of Python's re.split in Clojure (with capturing parentheses)
If you use capturing parenthesis in the regular expression pattern in Python's re.split() function, it will include the matching groups in the result (Python's documentation).
I need this in my ...
6
votes
5answers
242 views
Can this regex for checking strong password be improved?
^(?=^.*[a-z])(?=^.*[A-Z])(?=^.*[0-9])(\S{8,})(?<!\s)$
Is there any way to make this regex more concise? Ensures a password has lowercase, uppercase, digit and is at least 8 characters, ...
1
vote
1answer
122 views
Need regex wizard to improve this - eliminating unwanted namespaces
Techies--
I know there's a better way to do this, but need an infusion of genius!:-) I am trying to eliminate unwanted namespaces. This code works, but its remedial and redundant.
string sPattern = ...
1
vote
1answer
181 views
Replacing the first n occurrences of a term
I originally posted this question on Stack Overflow and it was suggested that it be moved here
Inspired by this question I thought to write my own jQuery function that would replace the first n ...
1
vote
0answers
214 views
Extension Method for Creating Types from Regular Expression Match Groups
I've been doing some parsing with regular expression named capture groups and decided it might make sense to write an extension to handle this.
The code below will create an instance of a specified ...
1
vote
1answer
108 views
Improving a shortcode replacement routine PHP and regex
I am using wordpress to allow a client to enter a curriculum vitae and have it output the correct and consistent html formatting:
So I have a plain text box custom field and am having them enter in ...
1
vote
2answers
160 views
I need help to improve this REGEX (repetead characters and space after punctuation)
I'm trying to "sanitize" a textarea input by disallowing repetead characters like "!!!", "???", etc. add spaces after commas, and I would like to optimize the code because I'm not a PRO at this...
...
1
vote
1answer
39 views
Regex Refinement
I'm trying to parse addresses out of blocks of text, and have the following expression to do so:
/\d+\s(?:[sewnSEWN]\.?\s)?[\d\w]+\s(?:(?:[\d\w]+\s){0,3})?\w+\.?/
It will currently parse addresses ...
4
votes
1answer
205 views
JavaScript replace
I am not sure the square brackets are correct (although it has not yet failed some simple tests). I would also like to reduce and simplify this code to one line if practical. I think the code is self ...
1
vote
1answer
158 views
Pirate Bay name and magnet mailer
So, first time I try PHP. Thought I'd set a goal for myself, divide it up in smaller problems and start googling. So yes I got it to work, very happy.
But, it is rather crude and ugly. So now I would ...
3
votes
1answer
171 views
Unicode parsing in PHP
Firstly, apologies if this is not the correct type of question for here, I had it on the stackoverflow but it was closed with a suggestion I post here.
I’m in the process of converting from Latin 15 ...
2
votes
2answers
136 views
Add getters and setters to a set of variables
Any improvements are welcome.
a.bat
sed -r "s/private (.*) (.*);(.*)/&\npublic \1 get\u\2(){return \2;}\npublic void set\u\2(\u\2){this.\2=\u\2;}\n/" "%~1">"%~2"
in:
private String ...
2
votes
3answers
740 views
Better implementation of a simplified regular expression engine?
Task:
On an alphabet set [a-z], a simplified regular expression is much simpler than the normal regular expression.
It has only two meta characters: '.' and '*'.
'.' -- exact one arbitrary ...
3
votes
1answer
195 views
I'm trying to escape some XML to be used with SOAP
I'm attempting to escape ampersands from a string before passing to PHP's SimpleXMLElement->addChild() for use with some SOAP webservices, but I don't want to double escape them. I'm getting these ...
2
votes
2answers
116 views
Bulleted list from dashes
Let's keep this simple.
Input:
- abc
- def
- ghi
Desired output (whitespace optional):
<ul>
<li>abc</li>
<li>def</li>
<li>ghi</li>
...
2
votes
2answers
176 views
Replace match inside tags
The problem I want to solve is to replace a given string inside tags.
For example, if I'm given:
Some text abc [tag]some text abc, more text abc[/tag] still some more text
I want to replace abc ...
3
votes
1answer
286 views
Simplify regular expression? (Converting Unicode fractions to TeX)
Background
I'm converting Unicode text to TeX for typesetting. In the input, I'm allowing simple fractions like ½ and ⅔ using single Unicode characters and complex fractions like ¹²³/₄₅₆ using ...
0
votes
1answer
471 views
Python program for converting scientific notation to fixed point
I had to replace all instances of scientific notation with fixed point, and wrote a Python script to help out. Here it is:
#!/usr/bin/python2
# Originally written by Anton Golov on 29 Jan 2012.
# ...
4
votes
3answers
156 views
How to determine the order of letters by regex?
I want to write a regular expression to determine whether a given string is uppercase and sorted in non-descending order.
^A*B*C*D*E*F*G*H*I*J*K*L*M*N*O*P*Q*R*S*T*U*V*Q*X*Y*Z*$
I was just wondering ...
4
votes
3answers
251 views
Checking a HTML element's class
$('pre').each(function(index) {
var c = $(this).attr("class");
if (!c) {
return true;
}
// Match only Javascript code snippets
if (!c.match(/brush: js; class-name: ...
1
vote
1answer
118 views
Help me optimize this code using Regular Expressions in C#
I have a requirement to capture string in a specific format of * [Numeric Digits] *. This is how I have done right now but I think it would be faster with Regular Expressions. I dont have a lot of ...
2
votes
2answers
218 views
Code Improvement: Copy Regex named capture groups to strongly typed object
This code works to copy named capture groups of a Regex to the same named properties of a strongly typed object. However, it's not pretty. Someone mentioned I should use polymorphism to at least ...
2
votes
1answer
105 views
filter out password in xml string
We're storing the xml communications with an external service in a text in the db and in a before_create I've got the following:
# filter opera password
def remove_password!
...
1
vote
0answers
417 views
C preprocessor regular expression
I parse preprocessor conditions using the regular expressions. First all, I match all preprocessor directives with the regex
@"# *(?<Directive>if|elif|ifdef|ifndef) .*"
I do not need else, ...