regex

Regex Pattern for a File Name

A user can put a file in the server if the file name matches the following criteria: It has to start with abc, then a dot, and a number. Valid file names: abc.2344 abc.111 Invalid: abcd.11 abc.ab12 What would be the regex? I can't just use abc.*. ...

Validating regular expression without catching exception?

In a .NET application (written in C#) I have a UI with a list and a text box used to enter a filter string to filter what is displayed in the list. I refresh the filter as the user types. I now want to allow use of regular expressions in the filter string, which poses a problem. As the user types the expression it may be invalid, for in...

Regex for URL with back slash in the end

I want a regrex for URl like this -- http://stackoverflow.com/ with allows only backslash in the end Thanks ...

Negate characters in Regular Expression

How to write a regular expression with the following criteria? without Numbers Special Characters Space ...

Regexp MySql- Only strings containing two words

Hi I have table with rows of strings. I'd like to search for those strings that consists of only two words. I tried few ways with [[:space:]] etc but mysql was returning three, four word strings also ...

How do we create such a regular expression to extract data?

<br>Aggie<br><br>John<br><p>Hello world</p><br>Mary<br><br><b>Peter</b><br> I'd like to create a regexp that safely matches these: <br>Aggie<br> <br>John<br> <br>Mary<br> <br><b>Peter</b><br> This is possible that there are other tags (e.g. <i>,<strike>...etc ) between each pair of <br> and they have to be collected just like the <b...

Replacing // comments with /* comments */ in PHP

Hi, I'm creating a CSS generator in PHP which uses CSSX (yep, they are my idea) files (with a special syntax). One feature is 'short comments': body { font-family: Georgia; //I really like this font! } Now I want to replace this comment with a /* ... */ comment, so the output is like this: body { font-family: Georgia; /*I re...

Regex To Match &amp;entity; or &amp;#0-9; And Capture &amp;

I'm trying to do a replace on the following string prototype: "I&amp;lsquo;m singing &amp; dancing in the rain." The following regular expression matches the instance properly, but also captures the character following the instance of &amp. "(&amp;)[#?a-zA-Z0-9;]" captures the following string from the above prototype: "&amp;l". How can...

Updating Linq to XML element values concatination issues

I am trying to write a app.config / web.config error correcting app that will audit our developers applications for incorrect environment settings. I am using Linq to XML to accomplish this and I am hitting a snag. var query = from el in doc.Descendants().Element("SMTPHost") select el; foreach (XElement host in query) { ...

Parse subtitle file using regex C#

I need to find the number, the in and out timecode points and all lines of the text. 9 00:09:48,347 --> 00:09:52,818 - Let's see... what else she's got? - Yea... ha, ha. 10 00:09:56,108 --> 00:09:58,788 What you got down there, missy? 11 00:09:58,830 --> 00:10:00,811 I wouldn't do that! 12 00:10:03,566 --> 00:10:07,047 -Shit, that's...

Extracting some data items in a string using regular expression

<![Apple]!>some garbage text may be here<![Banana]!>some garbage text may be here<![Orange]!><![Pear]!><![Pineapple]!> In the above string, I would like to have a regex that matches all <![FruitName]!>, between these <![FruitName]!>, there may be some garbage text, my first attempt is like this: <!\[[^\]!>]+\]!> It works, but as you...

How to find empty method/class XML summaries in Visual Studio?

i have noticed a number of empty method and class summary sections throughout a solution. It's rather large, hundreds of files/classes in a dozen projects. The empty summaries look something like this: ///<summary> ///</summary> My question is: How do i form a regex expression in the Visual Studio file search to find all of the empt...

Perl - Why does shift lose its value after being used?

This code works - It takes an array of full txt file paths and strips them so that when $exam_nums[$x] is called, it returns the file name for (0..$#exam_nums) { $exam_nums[$_] =~ s/\.txt$//; #remove extension $exam_nums[$_] =~ s/$dir//g; #remove path } When I try to do this for a single variable, it doesn't work. I'm calling a sub...

Deleting new lines with regular expression from Ant task

I've posted to 2 forums already (CodeRanch and nabble) and no one has responded with an answer .... so stack overflow ... you are my last hope. All I'm trying to do is delete the "\n" from a file using an Ant task. There simply is a bunch of empty lines in a file and I don't want them there anymore ... here is the code I used .. <re...

Regex Pattern Matching

Possible Duplicate: Regex Pattern for a File Name A user can put a file in the server if the file name matches the following criteria: It has to be abc or it should start with abc, then a dot, and a number. Valid file names: abc abc.2344 abc.111 Invalid: abcd abcd.11 abc.ab12 What would be the regex? abc.\d+...

How to remove any html tags with nothing but optional whitespace between them

I need to clean up some VERY ugly html (think < span>< /span> < em>< /em> < em> < /em> < strong>< /strong> ) over and over again... I'm looking for a nice and easy preg_replace to eliminate any html tags that contain optional whitespace between them. Your assistance is greatly appreciated! Oh, and just found this beauty: < p>< strong...

PL/SQL key-value String using Regex

I have a String stored in a table in the following key-value format: "Key1☺Value1☺Key2☺Value2☺KeyN☺ValueN☺". Given a Key how can I extract the Value? Is regex the easiest way to handle this? I am new to PL/SQL as well as Regex. ...

Turn a string into a regexp that matches the plain string, in DrScheme

I want to split a string based on a non-regular expression. My input is a plain string. So, for example, given the input "hello.*there" and ".*", I want the result ("hello" "there"). Doing this obv doesn't work: (regexp-split (regexp sep) str)) since it will try to match the regular expression .*. How do I escape sep to nullify any r...

Problem in using Sed to remove leading and trailing spaces

Hi all, I am using the following code to remove both leading and tailing spaces from all lines of a file A.txt sed 's/^[ \t]*//;s/[ \t]*$//' ./A.txt > ./B.txt The problem occurs on the lines where there is a t in the beginning or at the end. So say for example, the original line that starts with the string "timezone" becomes "imezon...

Installing new libraries on an OS X machine via terminal

I'm looking at using the tre tool provided at http://laurikari.net/tre/. I'm trying to install it on my Mac OS X box via the terminal. I've followed what I believe to be the regular path to install a new library - ./configure, sudo make, sudo install. Everything seems to go swimmingly. When I then go to access the library in c, I rec...