regex

Library to generate text from a regular expression in Java

Yup, you read that right. I need a library that is capable of generating random text from a regular expression. So the text should be random, but be matched by the regular expression. It seems it doesn't exist, but I could be wrong. Just a an example: that library would be capable of taking '[ab]*c' as input, and generate samples such a...

simple regex help php

Hi, I have a string Like this: MyText (1,151) I would like to get with regex only the value inside (), in this case only: 1,151. I know it is simple but I am not good with regex. Thanks! ...

Design of an Alternative (Fluent?) Interface for Regular Expressions

I've just seen a huge regex for Java that made me think a little about maintainability of regular expressions in general. I believe that most people - except some badass perl mongers - would agree that regular expressions are hardly maintainable. I was thinking about how this situation could be fixed. So far, the most promising idea I h...

QRegexp idiosyncracies (compared to perl): How can I write this regexp without the lazy quantifier?

I have the following regular expression that works fine in perl: Classification:\s([^\n]+?)(?:\sRange:\s([^\n]+?))*(?:\sStructural Integrity:\s([^\n]+))*\n The type of data format this string is supposed to match against is: Classification: Class Name Range: xxxx Structural Integrity: value Classification: Class Name Struc...

Need help converting a multi-language regular expression to detect a numeric range

I've created a regular expression that matches any numeric value (with leading or trailing spaces) that contains ascii or arabic characters. Now I need to modify it to only match a certain range of values (e.g. 1900-1950). (^\s*-?\d+\s*$)|(^\s*-?[\u0660-\u0669]+\s*$) I'm pretty stuck. Anyone have any suggestions? ...

Is there a better Regex for parsing DTD

I've got the DTD for OFX 1.03 (their latest version despite having developed and released 1.60, but I digress...) I would like to use regex to have groups that split an entity, element, other tags into its parts for further processing such that I would take a tag like this: <!ENTITY % ACCTTOMACRO "(BANKACCTTO | CCACCTTO | INVACCTTO)"> ...

Simple regex - replace quote information in forum topic in C#

Hi! This should be pretty straightforward I would think. I have this string: [quote=Joe Johnson|1]Hi![/quote] Which should be replaced with something like <div class="quote">Hi!<div><a href="users/details/1">JoeJohnson</a></div></div> I'm pretty shure this is not going very well. So far I have this: Regex regexQuote = new Regex(...

Regex: Insert a value in a capture group based on a conditional match?

First, this topic is a general regex question, but applies to a specific product - VirtualURL.NET (.NET HttpModule). I am using this product to do regex URL rewriting. I have a situation which I am attempting to accomplish in a single regex rule. I am matching against the following URLs: ~/directory/page.aspx?id=idval ~/directory/pag...

Question on Whitespace Filter Regex (it's simple, just a small addition needed)

Hey guys, I have a Regex based whitespace filter on an ASP.NET MVC application, and it works perfectly, too perfectly. One of the things that gets filtered are the \r\n characters. This effectively makes everything in one line of source code, which I love because I don't have to deal with quirky CSS because of the whitespace, but in cer...

preg_replace out CSS comments?

I'm writing a quick preg_replace to strip comments from CSS. CSS comments usually have this syntax: /* Development Classes*/ /* Un-comment me for easy testing (will make it simpler to see errors) */ So I'm trying to kill everything between /* and */, like so: $pattern = "#/\*[^(\*/)]*\*/#"; $replace = ""; $v = preg_replace($pattern...

matching a line with a literal asterisk "*" in grep

Tried $ echo "$STRING" | egrep "(\*)" and also $ echo "$STRING" | egrep '(\*)' and countless other variations. I just want to match a line that contains a literal asterisk anywhere in the line. ...

Nginx rewrite for URI querystring value

I changed my website platform and i am now getting hits from google pointing to the old location of tag searches on my site. Basically i need to point: http://www.website.com/articles/Subject%3Alist=Music-Oldies&amp;review_state=published to: http://www.website.com/tags/Music-Oldies ..in my Nginx website file. Only the tag 'Music-o...

Get filename from Unix "ls -la" command with regexp?

Hi, How can I produce a regular expressions pattern that returns the filename from any one of these lines? (I will search one line at a time). drwxrwxrwx 4 apache apache 4096 Oct 14 09:40 . drwxrwxrwx 11 apache apache 4096 Oct 13 11:33 .. -rwxrwxrwx 1 apache apache 16507 Oct 17 10:16 .bash_history -rwx...

Is there some way of escaping characters in Groovy regexes?

Is there someway of escaping characters in Groovy regexes? It would be nice to write a single backslash instead of 4. ...

How to find last occurence of a number in a string using Ruby?

Using Ruby... Given a String x = "blah_blah.do.dah[4543]junk_junk" How do I remove all text after the last number/digit? I thought the easiest way to do this might be by finding the index of last occurence and then removing everything after that index. However, I can't seem to figure out how to obtain that index. All my attempts at u...

PHP - Replace strings in first array with values from second array

For some reason I'm struggling with this. I have the following 2 arrays and I need to take the array values from the $img array and insert them in order into the $text array, appending/replacing the %img_ tags, like so: $text = array( 0 => "Bunch of text %img_ %img_: Some more text blabla %img_", 1 => "More text %img_ blabla %i...

What is the C# equivalent of java.util.regex?

I am converting Java code to C# and need to replace the use of Java's regex. A typical use is import java.util.regex.Matcher; import java.util.regex.Pattern; //... String myString = "B12"; Pattern pattern = Pattern.compile("[A-Za-z](\\d+)"); Matcher matcher = Pattern.matcher(myString); String serial = (matcher.matches()) ? matcher.grou...

NSPredicate and simple Regular Expression problem

I'm having problems with simple NSPredicates and regular expressions: NSString *mystring = @"file://questions/123456789/desc-text-here"; NSString *regex = @"file://questions+"; NSPredicate *regextest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex]; BOOL isMatch = [regextest evaluateWithObject:mystring]; In the above exa...

String matching in python with re

I have a file in this structure: 009/foo/bar/hi23123/foo/bar231123/foo/bar/yo232131 What i need is to find the exact match of a string; e.g. only /foo/bar among /foo/bar/hi and /foo/bar/yo One solution came up in my mind is like to check for ending "/" for the input string. Because if there is ending "/" in the possible results, that...

Simple regex negation

Trying to match ONLY the first character in the sample below. Sample string: C/C++/Objective C/Objective-C/ObjectiveC/objectiveC My faulty regex: (?![O|o]bjective[ |-]?)C(?!\+\+) Doh. ...