regex

Regular expression incorporating an exclusion (ie "does not contain") for grep

I'm trying to filter webserver log files using grep. I need to output all lines containing 65.55. but exclude those matching lines which contain msnbot. My starting point is this - but it doesn't work: grep "^.*65\.55\..*(!msnbot).*$" ex100101.log > results.txt I'm using grep for Windows (hence double quotes) but I doubt this matter...

Regex for validating a string with pre-specified special characters

I am looking for a regex to validate a string. I want to allow numbers, alpha characters, spaces and any of the following characters in any order: + - ( ) , I would be grateful if someone could help. thanks ...

Regular expression from font to span (size and colour) and back (VB.NET)

Hi, I am looking for a regular expression that can convert my font tags (only with size and colour attributes) into span tags with the relevant inline css. This will be done in VB.NET if that helps at all. I also need a regular expression to go the other way as well. To elaborate below is an example of the conversion I am looking for...

How can I get the file extensions from relative links in HTML text using Perl?

For example, scanning the contents of an HTML page with a Perl regular expression, I want to match all file extensions but not TLD's in domain names. To do this I am making the assumption that all file extensions must be within double quotes. I came up with the following, and it is working, however, I am failing to figure out a way to e...

Rewrite Query String

Hello, I am trying to write some mod_rewrite rules to generate thumbnails on the fly. So when this url example.com/media/myphoto.jpg?width=100&height=100 the script should rewrite it to example.com/media/myphoto-100x100.jpg and if the file exists on the disk it gets served by Apache and if it doesn't exist it is called a script t...

Regex for [a-zA-Z0-9\-] with dashes allowed in between but not at the start or end

Update: This question was an epic failure, but here's the working solution. It's based on Gumbo's answer (Gumbo's was close to working so I chose it as the accepted answer): Solution: r'(?=[a-zA-Z0-9\-]{4,25}$)^[a-zA-Z0-9]+(\-[a-zA-Z0-9]+)*$' Original Question (albeit, after 3 edits) I'm using Python and I'm not trying to extract t...

How do I sort a directory by time, and display the last four image files matching a pattern with php?

I have a directory that will be getting updated frequently, I want to display the last four images files uploaded, which match a certain pattern, on my php page. Is this possible without having to perform a sort on every single image within the directory? Many thanks! ...

PHP's preg_replace where the replacement is an arbitrary function of the match

Suppose I want to replace occurrences of "foo" with "oof": $s = "abc foo bar"; echo preg_replace('/(foo)/', strrev("$1"), $s); Instead of "abc oof bar" I get "abc 1$ bar". In other words, it's passing the literal string "$1" to the strrev() function, instead of the regex match, "foo". What's the best way to fix this problem in the ab...

string "search and replace" using a .NET regex

I need to do a 2 rule "replace" -- my rules are, replace all open parens, "(" with a hyphen "-" and strip out all closing parens ")". So for example this: "foobar(baz2)" would become "foobar-baz2" I currently do it like this -- but, my hunch regex would be cleaner. myString.Replace("(", "-").Replace(")", ""); ...

I need to Split a string based on a complex delimiter

In C# I need to split a string (a log4j log file) into array elements based on a particular sequence of characters, namely "nnnn-nn-nn nn:nn:nn INFO". I'm currently splitting this log file up by newlines, which is fine except when the log statements themselves contain newlines. I don't control the input (the log file) so escaping them ...

Can java.util.regex.Pattern do partial matches?

Hi all, Is it possible to know if a stream/string contains an input that could match a regular expression. For example String input="AA"; Pattern pat=Pattern.compile("AAAAAB"); Matcher matcher=pat.matcher(input); //<-- something here returning true ? or String input="BB"; Pattern pat=Pattern.compile("AAAAAB"); Matcher matche...

using sed to replace whole word containing '='?

EDIT i have something like this in a file: imagecolor=0 arrayimagecolorcopy=0 arrayimagecolorcopy3d=0 when i use sed -i -e 's/imagecolor=0/imagecolor=1/' it will change 1 and 2 line. But i only want it to replace first line. i also tried sed with \< \ > and \b \b, but no luck. Could it be the '=' sign? Do we have something like -w ...

What is a better way to write this regular expression?

I am converting XML children into the element parameters and have a dirty regex script I used in Textmate. I know that dot (.) doesn't search for newlines, so this is how I got it to resolve. Search language="(.*)" (.*)<education>(.*)(\n)?(.*)?(\n)?(.*)?(\n)?(.*)?</education> (.*)<years>(.*)</years> (.*)<grade>(.*)</grade> Replace g...

Multiple calls to preg_replace alters result

I have a bunch of files that were named in a somewhat standard format. The standard form is basically this: [integer]_word1_word2_word3_ ... _wordn where a word could really be anything, but all words are separated by an underscore. There is really only 3 things I want to do to the text: 1.) I want to modify the integer, which is al...

Big problem with regular expression in Lex (lexical analyzer)

Hi, I have some content like this: author = "Marjan Mernik and Viljem Zumer", title = "Implementation of multiple attribute grammar inheritance in the tool LISA", year = 1999 author = "Manfred Broy and Martin Wirsing", title = "Generalized Heterogeneous Algebras and Partial Interpretation...

Extracting Text from between parentheses in PHP using preg_replace

I am trying to take a string of text like so: $string = "This (1) is (2) my (3) example (4) text"; In every instance where there is a positive integer inside of parentheses, I'd like to replace that with simply the integer itself. The code I'm using now is: $result = preg_replace("\((\d+)\)", "$0", $string); But I keep getting a ...

Need a regular expression to parse a text body

Hi guys, I need a regular expression to parse a body of text. Basically assume this that we have text files and each of which contains random text but within the text there would be lines in the following formats - basically they are a format for denoting flight legs. eg: 13FEB2009 BDR7402 1000 UUBB 1020 UUWW FLT This line of text i...

RegEx: Split String at Capitalized Letters and Non-capitalized letters to Create Small Cap Fonts

So i've purposefully stayed away from RegEx as just looking at it kills me...ugh. But now I need it and could really use some help to do this in .NET (C# or VB.NET). I need to split a string based on capitalization or lack thereof. For example: I'm not upPercase "I" "'m not up" "P" "ercase" or FBI Agent Winters...

Explain a block of crazy JS code inside Sizzle(the CSS selector engine)

So, here is the function for pre-filtering "CHILD": function(match){ if ( match[1] === "nth" ) { // parse equations like 'even', 'odd', '5', '2n', '3n+2', '4n-1', '-n+6' var test = /(-?)(\d*)n((?:\+|-)?\d*)/.exec( match[2] === "even" && "2n" || match[2] === "odd" && "2n+1" || !/\D/.test( match...

Regex to slice filename contain string and numerical

hi, can anybody help me solve this : i got $filename= "index 198.php"; i use this and failed preg_match(" [a-zA-Z0-9]", $filename, $output); what kind of regex pattern i have to use so the $output array will be consist a number only value. ...