regex

How to extract all fields from create sql statment using .Net?

I am creating a windows application using VB.Net and this application will take a SQl create .sql file as a parameter and will return all fields and their data types inside in a list or array. Example: USE [MyDB] GO /****** Object: Table [dbo].[User] Script Date: 07/07/2009 10:16:48 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFI...

sed to replace TTLs in a tinydns zonefile?

I'm working to replace a large set of TTLs inside some tinydns zonefiles. Regardless of what the TTL is currently set to, I want it to become 900. I'm looking for some sed magic, and I'm almost there it seems. I have about 50 hostnames to replace the TTL, and the zones are sporadically assigned. The lines in the zonefiles don't need ...

Inserting a line to a known block of text

I define a 'block' of text as all lines between start of file, newline or end of file: block1 block2 block3 anotherblock4 anotherblock5 anotherblock6 lastblock7 lastblock8 Any text can occupy a block - it is unknown what lines are there. I tried to write a shell script to insert a new line at the 2nd block, but since sed doesn't lik...

extract fileName using Regex

Hello everyone, If I want to match only fileName, i.e, in C://Directory/FileName.cs, somehow ignore everything before FileName.cs using Regex. How can I do it? I need this for a Compiled UI I am working on ... can't use programming language as it only accepts Regex. Any ideas? ...

How can I extract abbreviations from a file using Perl?

I need to extract certain Abbreviations from a file such as ABS,TVS,and PERL. Any abbreviations which are in uppercase letters. I'd preferably like to do this with a regular expression. Any help is appreciated. ...

Escape double quotes of HTML attributes output by PHP

Often when writing PHP I'll have it output some HTML like this - echo "<a href="../" title="link title">".$link_text."</a>"; Obviously this won't parse as I need to escape the double quotes in the attributes of the <a> element. Is there a regex that would quickly do this rather than me manually adding the backslashes? One other thing...

RegularExpressionValidator for multiple emails.

I'm validating a textbox for valid email with this: <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtMailCustom" Text="Invalid address" ValidationExpression="^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9] {1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$" runat="server" /> No...

RegEx for ICQ UIN

What RegularExpressionValidator.ValidationExpression should I use to allow only ICQ UIN like input? xxx-xxx-xxx and xxx-xxx-xx and xx-xxx-xxx and xxxxxxxxx so on.. i.e. with dash as separator and without. ...

Improving Shell Script Performance

This shell script is used to extract a line of data from $2 if it contains the pattern $line. $line is constructed using the regular expression [A-Z0-9.-]+@[A-Z0-9.-]+ (a simple email match), form the lines in file $1. #! /bin/sh clear for line in `cat "$1" | grep -i -o -E "[A-Z0-9.-]+@[A-Z0-9.-]+"` do echo `cat "$2" | grep -m 1 ...

Regular expression, split string by capital letter but ignore TLA

I'm using the regex System.Text.RegularExpressions.Regex.Replace(stringToSplit, "([A-Z])", " $1").Trim() to split strings by capital letter, for example: 'MyNameIsSimon' becomes 'My Name Is Simon' I find this incredibly useful when working with enumerations. What I would like to do is change it slightly so that strings are only spli...

Are regular expressions worth the hassle?

It strikes me that regular expressions are not understood well by the majority of developers. It also strikes me that for a lot of problems where regular expressions are used, a lump of code could be used instead. Granted, it might be slower and be 20 lines for something like email validation, but if performance of the code is not desper...

Anybody also epriences problems with JAXB validation, when XSD contains regular expression character class \w?

Hi, We are using JAXB 1.0.6 (the project has started with JDK1.4 and this is the last compatible version) to create XML-Files from a XSD specification. The XSD defines an attribute "email" with the following regexp pattern. <xs:simpleType name="EmailAddress"> <xs:restriction base="xs:string"> <xs:minLength value="0"/> <xs:maxLengt...

How to construct this in regular expression

I have file names that end in yyyymmdd, eg: myFile.20090601, myFile20090708 , etc I want to grep for a pattern in all files from June 08 to July 07 of 2009, ie: 20090609 to 20090707 How can I do a regex in one go? I tried: grep 'myPattern' *20090(6(09|[1-3][0-9])|70[1-7]) ...

Using regular expressions

I am trying to match emails from one of my own sites using a regular expression. Using preg_match_all($pattern,$site,$array) the results I get are duplicate. So for example, using: $pattern = '/[\w-]+@([\w-]+\.)+[\w-]+/i'; I get: Array ( [0] => [email protected] [1] => [email protected] [2] => [email protected] [3] => sales@...

Regular Expressions for matching functions in javascript source code?

Is there any way to match a function block in javascript source code using regular expressions? (Really I'm trying to find the opposite of that, but I figured this would be a good place to start.) ...

Matching Nested Structures With Regular Expressions in Python

I seem to remember that Regular Expressions in DotNet have a special mechanism that allows for the correct matching of nested structures, like the grouping in "( (a ( ( c ) b ) ) ( d ) e )". What is the python equivalent of this feature? Can this be achieved using regular expressions with some workaround? (Though it seems to be the sor...

Regex: Named groups and replacements

There is a method Regex.Replace(string source, string pattern, string replacement) The last parameter supports pattern replacements such as ${groupName} and others (but I don't know the group name in the run-time). In my case I have the dynamically created pattern like: (?<c0>word1)|(?<c1>word2)|(?<c2>word3) My purpose is to repla...

Find matched directories using a list of regular expressions

I have an IEnumerable<DirectoryInfo> that I want to filter down using an array of regular expressions to find the potential matches. I've been trying to join my directory and regex strings using linq, but can't seem to get it right. Here's what I'm trying to do... string[] regexStrings = ... // some regex match code here. // get all ...

How to split a path platform independent?

I'm using the following code to get an array with all sub directories from a given path. String[] subDirs = path.split(File.separator); I need the array to check if certain folders are at the right place in this path. This looked like a good solution until findBugs complains that File.separator is used as a regular expression. It see...

Turning a string match requirement into a Regular Expression

Hello. I'm having a problem writing a regular expression. How could I write the following: start with an optional access level (a digit from 1 to 5) followed by a space then a user name consisting of between 3 and 5 small letters followed by between 3 and 5 digits then one or more spaces and then a four digit pin number then one...