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
21 views
Using Regexp to select the date from a string [on hold]
I have a string with date details with time, but I would like to show the day information alone. For that, I use the regexp to select the date. Can anyone tell me the regexp, and if what is used is ...
2
votes
1answer
42 views
Regex-ing an array
I am new using regex expression. After much digging I came up with this code. I would like to know if this is the correct way. I want to search in Joomla for some html tags with specific class and ...
3
votes
1answer
58 views
Deserialize an email header into key-value pairs
I've created a function that will deserialize an email header into a list of key-value pairs. I've run numerous tests using MS Office Outlook 2010 and MS Office 14.0 Object Library, all of which were ...
2
votes
2answers
57 views
Phone Number Extracting using RegEx And HtmlAgilityPack
I've written this whole code to extract cell numbers from a website. It is extracting numbers perfectly but very slowly, and it's also hanging my Form while Extracting.
...
1
vote
0answers
26 views
Using URLs and RegEx for web scraper from a dictionary [closed]
I have dozens of functions which GET/POST to some URLs and extract data using RegEx. The URLs and regular expressions were hard-coded earlier but now I moved all of them to a dictionary. I then saw ...
4
votes
1answer
44 views
Split a string of hostnames, expand from regex, return non-duplicated names in original order
I have the following function. It can be passed a candidate_string such as the following examples:
"device1 device2"
"device1"
"device.*"
"device.region"
"device[123]
Assume that target_list ...
11
votes
2answers
249 views
6
votes
1answer
46 views
Expand hostnames from a string of hostnames and/or regex
This code will be passed a string which will contain one or more hostnames.
A hostname can be
dotted-decimal
plain name (like my_host)
FQDN or even partially ...
2
votes
2answers
25 views
Performance of RegExp vs Rune Loop
I was recently talking to someone about a function I wrote to mimic (very basically) the string interpolation function String.Format() found in the C# language. ...
3
votes
2answers
44 views
Align text (left, center, right) without additional packages
I wrote this short subroutine to left, center, right-align a multiline string.
How can I make it better (shorter, prettier, optimized)? Can you offer some suggestions?
...
1
vote
1answer
74 views
Two implementations of website internationalization
I have attempted to create an internationalization system for my PHP framework that I'm working on.
For the purpose I decided I will be using MySQL to store languages and translations. Respectively I ...
2
votes
1answer
51 views
Process a line in chunks via Regular Expressions with Ruby
I'm writing a Ruby script to reverse engineering message log files. They come from an external system with the following characteristics:
Each line of the log file has at least one message.
Each ...
8
votes
3answers
95 views
Match Simple Sentence or Partial Sentence
Description
Match a Simple Sentence or a partial sentence
Suitable for matching
People Names (to some extent)
Product Titles (to some extent)
Correct use of apostrophe (to some extent)
...
7
votes
3answers
344 views
Replacing non-ASCII characters
I wrote a C# program to remove non-ASCII characters in a text file, and then output the result to a .NonAsciiChars file.
The input file is in XML format. In fact, ...
5
votes
1answer
76 views
Do I have too many regexes in my validation logic?
The below function uses Javascript to validate a Belgian telephone number and format it according to the guidelines for phone number formatting.
...
2
votes
2answers
103 views
Validate multiple regexes without a for loop in JavaScript
For a project, I need to validate a VAT number against the correct algorithm. I found a library for this here (freeware, so I should be able to reuse it) that I'm grateful exists. However, I feel like ...
5
votes
3answers
152 views
Regex to validate font names
/((([\w -]+)|("[\w -]+"))( *, *)?)+/
http://refiddle.com/18ql
I'm trying to use a PHP regex to sanitize a user input for a list of fonts. The above one seems to ...
6
votes
3answers
129 views
Pattern tokenization program
I am writing this program to try and get some practice at C++ and correct and proper styling.
This code is meant to take user input from a pip and then run it through the program. The user enters a ...
5
votes
1answer
135 views
Generating the pretty bit at the end of a URL
I'm having a dip into F# and am attempting not to write it like it's C#.
One area that bothers me is using members of System.String. These often need to be chained ...
5
votes
3answers
130 views
Cleaner or better readability in URL composition
I have a URL that is hardcoded via a config which I extract into a config:
...
3
votes
1answer
94 views
Automatic condensing of whitespace in HTML
One of the things that has occurred to me more recently is that if you add up all of the bandwidth that is taken up by thousands of users downloading the newlines and tabs used to make HTML source ...
6
votes
1answer
147 views
Convert WKT representations of geometries into GeoJson
I am working on a class library in C# to convert WKT to GeoJson. I am getting shapes in WKT out of MSSQL. A lot of the shapes ...
2
votes
1answer
48 views
Is this regular expression optimizable (reduced match steps) [closed]
Requirement that need to handle:
only ascii letters in lower register [a-z], digits [0-9], ...
25
votes
10answers
3k views
What are some indicators that I was over-thinking my solution to this problem?
This question is a cross between career question and a code review. I was uncertain where to ask, but since there is code involved I went with CodeReview.
I’m going through the process of technical ...
6
votes
1answer
55 views
Canonicalizing a large set of addresses using many regex substitutions
I have a script that is standardizing a large amount of data in the database. The standardization involves applying over 500 regular expressions to the data.
Here is some quick pseudocode:
...
2
votes
1answer
37 views
Cheat Code Scraper
During breaks, I find myself playing Emerald version a lot and was tired of having to use the school's slow wifi to access the internet. I wrote a scraper to obtain cheat codes and send them to my psp ...
7
votes
2answers
607 views
Optimizing and improving a username regex
I have created this regular expression to validate usernames which I need in my projects:
...
6
votes
5answers
1k views
Regex validation for Email Address
I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct:
Wiki Link Local_part
The local-part of the email address may use any of these ASCII ...
2
votes
1answer
62 views
More Pythonic version of finding substring with one glob-like expression
Giving the following example list the task is: find out whether the
second expression is in the first one. * shall be considered as a
wildcard for any ...
2
votes
1answer
91 views
Preg_match pattern for user input filtering
My users may need to supply a 'disease category' to my site. I need to let them use all alphanumeric characters, hyphens and single quotes. Would someone review this to see if they feel it's ...
5
votes
1answer
48 views
Negative Lookbehind Regex
I have the following code which attempts to match all strings like "*SOMESTRING" (which can include numeric values), but not "*SOMESTRING*". For this I am using a negative lookahead as follows;...
2
votes
1answer
51 views
Is this `img` creator decently secure from XSS?
This is being used now, seems decent to me but I'm curious.
...
2
votes
2answers
47 views
Determine if a path matches a pattern
I have been struggling with a regular expression involving path names. Immediately, this is a bit troublesome, owing to the embedded / in the pattern, but braces to the rescue.
First the convention ...
7
votes
2answers
247 views
Check whether a list of list of string fits a regex efficiently
I have the following structure for my object:
Word (Object)
Word (String)
List<Symbol>
Symbol (Object)
...
3
votes
1answer
72 views
Breaking after one of several string replaces occur
I have a script that matches a string against ~20 different regexs for the purpose of changing it. They are ordered and formed that the string will only ever match against one. How can I avoid ...
7
votes
3answers
170 views
VB6/VBA Declaration (Dim) Syntax Parser
As part of a project I'm working on, I've implemented a class that encapsulates the syntax for a vb6/vba Dim statement.
Given a line of code, the ...
1
vote
0answers
43 views
VerbalExpressions in Scala
I forked the original implementation of VerbalExpressions in Scala here: https://github.com/pathikrit/ScalaVerbalExpressions
I am looking forward to these things in the code review:
...
1
vote
2answers
80 views
Parsing BLAST output in XML format using Regular Expression
There many other better ways to parse BLAST output in .xml format, but I was curious to try using regex, even if it is not so straightforward and common. Here is the code how to extract translated ...
5
votes
1answer
69 views
Combining two indexOf and regex in to one
I have the following code that splits a combination of names on either the word and or the & ampersand:
...
5
votes
3answers
391 views
Regex match for a string in a URL
I feel like there is too much repetitive code going on here. All I am doing is doing a basic regex match for a string in the URL. If a match is found, I find an li with a class (.index, .grid, .type) ...
4
votes
2answers
58 views
Efficient use of regular expression and string manipulation
The following is my solution to Java vs C++. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle.
...
2
votes
1answer
143 views
4
votes
1answer
71 views
Converting snake_case to CamelCase
Is there an effective way, maybe with regex, to change the following text pattern?
I have a string like abc_def_ghi_jkl. I want to replace it to ...
1
vote
1answer
334 views
Is this a safe way to parse out HTML tag attributes?
I needed a super simple parser to get HTML attributes and their values. I didn’t want to load a big library or anything so I made this.
I realize I am making assumptions here, mainly:
Attribute ...
3
votes
1answer
78 views
How to simplify Regex with Data.Text?
This function tells that elements of content either (maybe) match regexes that you like or match regexes that you don't like.
This messy code requires ...
2
votes
1answer
36 views
Parsing playlists efficiently
I have this regexp working, simple, but I feel like it may not be the best way to code it. Basically, I have a playlist separated by line breaks returned as tcp data like so:
...
11
votes
4answers
1k views
What would be preferred aesthetically and performance wise?
Which one of these two would you prefer writing in your code?
This:
...
1
vote
4answers
164 views
Best way to comment regex
Regular expressions are one of the worst aspects of debugging hell. Since they are contained in string literals, It's hard to comment how they work when the expressions are fairly long.
Say I have ...
2
votes
2answers
123 views
Speeding up and fixing phone numbers from CSVs with Regex
I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a ...
4
votes
1answer
50 views
Communicating between plugins whilst maintaining context in Javascript
I'm making some changes to a JavaScript plugin on a site I've been made steward over. This main plugin has it's own sub-plugins and I'm trying to make certain aspects modular.
Currently, I'm ...