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
2k views

Disallowing repeated characters and space after punctuation

I'm trying to "sanitize" a textarea input by disallowing repeated 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
56 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+\.?/ ...
4
votes
1answer
2k 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
375 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 ...
2
votes
1answer
329 views

HTML downloader and parser for CR

This program downloads a Code Review HTML file and parses it. Could you review my program? Main.java ...
3
votes
1answer
728 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 ...
1
vote
2answers
187 views

Add getters and setters to a set of variables [closed]

Any improvements are welcome. a.bat ...
5
votes
2answers
8k views

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 ...
2
votes
1answer
1k views

Escaping XML to be used with SOAP [closed]

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 ...
2
votes
2answers
187 views

Sanitize DOM IDs

I needed to create a method that would sanitize DOM IDs based on the HTML 4 criteria (yeah, HTML 5 is a lot looser). Does this make sense? Did I get too cute with making it concise? Am I totally ...
2
votes
2answers
1k views

Bulleted list from dashes

Let's keep this simple. Input: - abc - def - ghi Desired output (whitespace optional): ...
2
votes
2answers
5k 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 ...
3
votes
1answer
1k 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 ...
2
votes
1answer
5k 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: ...
3
votes
3answers
5k views

How to determine the order of letters by regex? [closed]

I want to write a regular expression to determine whether a given string is uppercase and sorted in non-descending order. ...
4
votes
3answers
285 views

Checking a HTML element's class

...
3
votes
1answer
225 views

Capturing a string in a specific format

I have a requirement to capture a 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 ...
3
votes
2answers
665 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 ...
3
votes
1answer
459 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: ...
6
votes
3answers
731 views
2
votes
1answer
216 views

Clojure code adapted from map-invert

I wanted to do the following: Count the frequencies of words in a text (over 5 letters) Invert the map of words to frequencies, but group together words that have the same frequency in the inversion....
2
votes
2answers
748 views

Adding a zero to file names

I've recently discovered the power of sed; regular expressions seem like they'll take a lifetime to master. This tiny script uses both to add a zero before the single digit in file names. Can this be ...
2
votes
1answer
2k views

Evaluate/Refactor my ASP.NET XSS Security Helper Class

I am maintaining a site with significant security concerns and I wrote a helper class for validating potential XSS attacks. The ValidateRequest method is meant to ...
4
votes
3answers
22k views

Regular Expression replace specific characters

Does anyone know of a better / cleaner way to write the following: ...
6
votes
1answer
401 views

Regexes for Google App Engine

I want to review the URL routing for my appengine webapp: ...
2
votes
3answers
170 views

Best Regular Expression for a one or two values optionally divided by a certain character

I'm looking for the most concise regex that matches one or two 4-digit years in any the following setups: year year- -year year-year I can't think of anything slicker than this: ...
3
votes
1answer
140 views

Algebraic notation with RegEx

I've written an algebraic notation to use for moves in a game and I'm currently writing code to parse the information from the notation. I'm doing this using regExes. This is coded in HaXe. For ...
5
votes
4answers
5k views

Best way to replace a beginning and end character in Perl using Regular Expression?

I'm wondering if there is a simplier regex I could use in my code to remove the beginning and ending char in a line. Maybe combine some regex's? In this instance, it's a comma at the beginning and ...
1
vote
2answers
1k views

Improve on Regex replacing classnames

I am working on a small script for a mobile site. Is there any way to improve on the regex here? or remove it completely? ...
3
votes
3answers
306 views

Pinging the user requested host - is this code insecure?

...
2
votes
3answers
6k views

Regular Expression to remove blank lines

This is basically my first Ruby class, which is to remove all empty lines and blank times from a .txt file. A simple test case is also included. I tested the code and it works fine. But I did not ...
1
vote
2answers
143 views

Refactor 2 regular expressions in Javascript into 1 statement

I have the following code, which replaces " " <-- Spaces with "-" <-- Dash. Because some of the title text will be returned with more spaces, it converts it into 3 dashes. Examples of ...
5
votes
1answer
562 views

Processing XML configuration which stores regular expressions and format strings for a documentation tool

I'm investigating some feature for the ScalaDoc tool, which would allow library writers to link to documentation created by third party tools like JavaDoc. My idea is to have some (XML) configuration ...
3
votes
2answers
619 views

Brace pairing ({}[]()<>) cleanup/speedup

This is working as expected, except in the speed area + I need to make it more readable and shorter if possible, I probably have lot's of things I don't need :). Edit it is working now ...
1
vote
2answers
2k views

A faster way to look up for a url in a WebRequest/WebResponse html

What I'm trying to do here is get an RSS feed and append an Enclosure XML node to each item, which has a link to a video file (wmv). Try the below code with ...
6
votes
2answers
1k views

N-gram generation

I have the following code, but it's too slow. How can I make it faster? ...
2
votes
1answer
385 views

Function to convert a title to a slug

I'm creating a function that converts a title, to a URL slug. I'm not all to familiar with regular expressions, but I've done my best. Can you see any problems or improvements with the following ...
4
votes
1answer
314 views

Using Regex to parse a chat transcript

I need to classify each line as "announce, whisper or chat" once I have that sorted out I need to extract certain values to be processed. Right now my regex is as follow: ...
6
votes
2answers
7k views

Converting JSONP to JSON: Is this Regex correct?

I'm fetching a string that is JSONP, and looking to convert it to JSON. I'm using the following regular expression for matching (for removal) the padding on the JSON. ...
12
votes
4answers
52k views

Simplify splitting a String into alpha and numeric parts

Requirement: Parse a String into chunks of numeric characters and alpha characters. Alpha characters should be separated from the numeric, other characters should be ignored. Example Data: Input ...
6
votes
2answers
132 views

How to reduce this archive detection function and make it supports wildcards

The function below is called to determine if a given file is the archive of another file. I'm also looking for a way to supports wildcards. For example if the original log file is serverw3c.log and we ...
23
votes
5answers
23k views

Use of a regex stored inside a YAML file

I installed settingslogic and in the configuration file I put the regex for the email as follows: ...
11
votes
2answers
368 views

Is this a sufficient way to prevent script injections and other bad stuff in strings

Would this function be sufficient enough to remove all malicious code and foreign characters from a string? ...