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
2answers
28 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
63 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. ...
0
votes
1answer
36 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"""
...
13
votes
4answers
1k views
My regex 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 ...
2
votes
0answers
24 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
51 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
votes
1answer
37 views
Multiple of a number through a regular expression [closed]
How do I find if a string contains a number which is a multiple of 5 or not? Without converting/casting it to an integer?
1
vote
1answer
65 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
32 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
104 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
86 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
120 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
59 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
73 views
Regular Expression Generator
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
55 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 ...
2
votes
1answer
126 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
160 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
137 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
76 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
88 views
Matching a pattern in many lines of text, Java?
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
46 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
97 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 ...
2
votes
0answers
106 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)
{
...
2
votes
2answers
64 views
Trying to improve a working regex
I am extracting data from a text file. Some of the lines from which I want to extract the data consist of a text description with single spaces, followed by a multiple-space gap preceding four fields ...
0
votes
0answers
63 views
JavaScript regular expression literal as string literal
Please refer to this question for more discussion.
JavaScript string literal sometimes to many escaping slashes. The following address this problem by converting a regular expression literal into a ...
2
votes
1answer
101 views
Can I make a regex array to iterate through in C++?
I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this:
regex regex_a (".."); string rewrite_a = "($1/$2)";
regex regex_b (".."); ...
2
votes
1answer
105 views
Regular expression for application version
Only these formats are accepted.
1.1.1
1.1.1-r
1.1.1-b
1.1.1-r1
1.1.1-b1
I wrote this code. What don't I like in it? I used parentheses and now I have two groups. In fact, I don't need to do ...
0
votes
1answer
65 views
Improvment of and looping in a regular expression pattern
My implemented regex pattern contains two repeating symbols: \d{2}\. and <p>(.*)</p>. I want to get rid of this repetition and asked myself if there is a way to loop in Python's regular ...
1
vote
1answer
782 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
127 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
55 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
345 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 ...
2
votes
1answer
40 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
44 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
63 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
555 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
202 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
87 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
129 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
70 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
201 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
72 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
271 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
96 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
639 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
115 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 ...
2
votes
1answer
288 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
87 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
306 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
1k 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 ...