regex

map string position to line number in regex output

I'm working on a "grep-like" utility in Python for searching Oracle source code files. Coding standards have changed over time, so trying to find something like "all deletes from table a.foo" could span multiple lines, or not, depending on the age of that piece of code: s = """-- multiline DDL statement DELETE a.foo f WHERE f.b...

create a program that inputs a regular expression and outputs string(s) that satisfy that regular expression

I think that the title accurately summarizes my question, but just to elaborate a bit, instead of using a regular expression to verify properties of existing strings, I'd like to use the regular expression as a way to generate strings that have certain properties. The function doesn't need to generate every string that satisfies the r...

Assistance with Find and Replace Regex

I have a text file, and each line is of the form: TAB WORD TAB PoS TAB FREQ# Word PoS Freq the Det 61847 of Prep 29391 and Conj 26817 a Det 21626 in Prep 18214 to Inf 16284 it Pron 10875 is Verb 9982 to Prep 9343 was Verb 9236 I Pron 8875 for Prep 8412 that Conj 7308 you Pron 6954 Would one of you regex wizards kindly assist me in is...

Regular expression for host

Hi all How can I match with regular expression hosts like 123-45-67-89.dummy37.ipx.northtelecom.net.uk or q6415-ipbffx02alas.tokyo.ocx.wa.jp? Additional info, some samples (I modified some hosts for privacy reasons): abc953.internetdsl.uwnet.pl ip-200-200-200-200.static.puxdsl.pt.lu 123-123-45-45.cost.xligtik.se saul-wilhem-c-118-37....

URL Regex for PHP framework

I'm trying to get the controller, method and queries from a URL array. Something like this: 'home/news/[day]/[month]/[slug]/' I need some regex which will give me the following: Controller: home Method: News Arguments: day, month, slug For the arguments, it'd be nice if I could somehow get the name inside the brackets so I can put th...

What regex pattern do I need for this?

I need a regex (to work in PHP) to replace American English words in HTML with British English words. So color would be replaced by colour, meters by metres and so on [I know that meters is also a British English word, but for the copy we'll be using it will always be referring to units of distance rather than measuring devices]. The pat...

Apache Regex doesn't return first result.

I have the following URL: http://somedomain.com/aa/search/search.php I want it to return 2 selections, that of "aa" and that of "search/search.php". With the help of Regex Coach, I have made the following regular expression which targets these two just fine: /([a-z]{2})/(.*) However, when I use them in my htaccess file, the rewrit...

How to Check if a String is a "string" or a RegEx?

How can I check if a String in an textbox is a plain String ore a RegEx? I'm searching through a text file line by line. Either by .Contains(Textbox.Text); or by Regex(Textbox.Text) Match(currentLine) (I know, syntax isn't working like this, it's just for presentation) Now my Program is supposed to autodetect if Textbox.Text is in f...

How do I preserve the existing query string in a mod_rewrite rule

I'm trying to rewrite an url from: http://domain.com/aa/whatever/whatever.php to http://domain.com/whatever/whatever.php?language=aa However, depending on existing $_GET variables, it either has to be ?language or &language. To do this, I use 2 regexes with the [L] flag: RewriteRule ^([a-z]{2})/(.*\.php\?.*) /$2&language=$1 [L] Rewri...

Regex to check a string

Hi, I'm trying to check a string and then extract all the variables which starts with @. I can't find the appropriate regular expression to check the string. The string may start with @ or " and if it's started with " it should have a matching pair ". Example 1: "ip : "+@value1+"."+@value2+"."+@value3+"."+@value4 Example 2: @namePar...

How do I create a Perl regular expression to remove all characters before the first "<"?

I currently have this: tr/[.]+(?=<)//d which should remove all characters (represented by [.]+) up to the first "<", because I'm using a positive lookahead. But for some reason, it's removing all "." and "<" from the string. For the record, I am not processing HTML or XML with regular expressions. ...

regex - find specific text between 2 specified boundary

Hi, I'm trying to develop a regex that will detect recursive template calls in an xsl style sheet. So far, it has not been really successful. In the following code, I need to detect that template B is called recursively: <xsl:template name="A"> blah blha ?!@#?%$#^%?*?&(({}:"><;'[]\/.,./' <xsl:call-template name="B"> b...

Regex Match Constant

I am having some trouble with this regular expression, Can somebody maybe assist me with the regex... I want to match the following in the source of websites that have this line installed on there pages: The code should always match this exact match (It is a constant): <img src="http://www.domain.com/test.asp" width="1" height="1" /> ...

Use a RegularExpressionValidator to limit a word count?

I want to use an ASP.NET RegularExpressionValidator to limit the number of words in a text box. (The RegularExpressionValidator is my favoured solution because it will do both client and server side checks). So what would be the correct Regex to put in the RegularExpressionValidator that will count the words and enforce a word-limit? Fo...

C# Regex. This regex doesn't quite do the job.

I'm trying to split these into tokens and it's mostly there. I really want to split the primary tokens up like NIGHT, set, the xpath pattern, the value to assign to the xpath pattern, i.e. in the second one, 'high' and in the second one, 'taken-offline' and the '-' and '+'. NIGHT.set('.//idmef:Source[1]','+') NIGHT.set('.//idmef:Assess...

How can I replace intraline tabs with spaces, maintaining alignment?

I like to use spaces for indentation rather than tabs; replacing tabs at the beginning of a line is easy in sed or vim: s/^I/ /g But if there are tabs within a line (pretend the spaces are the width of the tab char): 'foo'^I ^I => 'bar', 'bazzle'^I => 'qux', Each tab doesn't correspond to a set number of spaces to maintain the...

Problem with regular expression using grep

I've got some textfiles that hold names, phone numbers and region codes. One combination per line. The syntax is always "Name Region_code number" With any number of spaces between the 3 variables. What I want to do is search for specific region codes, like 23 or 493, forexample. The problem is that these numbers might appear in the lon...

Parse html using C

I've been a big fan of the site and frankly this is the first time I ever came across a problem that Stackoverflow didn't have the answer to. I need to grab some content from an html(xhtml valid) page. I grab the page using curl and store it in memory. I played with the idea of using regex with the PCRE library, but simply I couldn't fi...

Regex for extraction in Python

I have a string like this: "a word {{bla|123|456}} another {{bli|789|123}} some more text {{blu|789}} and more". I would like to get this as an output: (("bla", 123, 456), ("bli", 789, 123), ("blu", 789)) I haven't been able to find the proper python regex to achieve that. ...

Recommended method for testing regular expressions?

I'm new to regular expressions, I've been able to write a few through trial and error so tried a few programs to help me write the expression but the programs were harder to understand than the regular expressions themselves. Any recommended programs? I do most of my programming under Linux. ...