regex

How do I check if a filename matches a wildcard pattern

I've got a wildcard pattern, perhaps "*.txt" or "POS??.dat". I also have list of filenames in memory that I need to compare to that pattern. How would I do that, keeping in mind I need exactly the same semantics that IO.DirectoryInfo.GetFiles(pattern) uses. EDIT: Blindly translating this into a regex will NOT work. ...

combine regex in ruby

Given this text: /* F004 (0309)00 */ /* field 1 */ /* field 2 */ /* F004 (0409)00 */ /* field 1 */ /* field 2 */ how do I parse it into this array: [ ["F004"],["0309"],["/* field 1 */\n/* field 2 */"], ["F004"],["0409"],["/* field 1 */\n/* field 2 */"] ] I got code working to parse the fir...

C# Regex to get the comments block out of pl/sql code

i want to extract the comments out of a string as a block. e.g. I have a PL/SQL code as: --comment1 select * from t_table; --i want comment 2; /*i want comment 3 */ --i want comment 4 OPEN data_cur; Here, i want all the single line and multiline comments before OPEN data_cur; but after select * from t_table; i.e. i want a full co...

C# regex to replace a delimiter by another one

I'm working on pl/sql code where i want to replace ';' which is commented with '~'. e.g. If i have a code as: --comment 1 with; select id from t_id; --comment 2 with ; select name from t_id; /*comment 3 with ;*/ Then i want my result text as: --comment 1 with~ select id from t_id; --comment 2 with ~ select name from t_id; /*com...

Highlight a list of words using a regular expression in c#

I have some site content that contains abbreviations. I have a list of recognised abbreviations for the site, along with their explanations. I want to create a regular expression which will allow me to replace all of the recognised abbreviations found in the content with some markup. For example: content: This is just a little test of ...

Regular Expression to replace line if exist, add line if not

I need to read through an Apache httpd.conf file, and find the following line: #LoadModule blah blah and uncomment it, i.e., replace it with LoadModule blah blah The catch here is that since the conf file can vary, there is a real possibility that the LoadModule line has already been uncommented. There is also a possibility that ...

Split SQL statements

Hello, I am writing a backend application which needs to be able to send multiple SQL commands to a MySQL server. MySQL >= 5.x support multiple statements, but unfortunately we are interfacing with MySQL 4.x. I am trying to find a way (hint: regex) to split SQL statements by their semicolon, but it should ignore semicolons in single...

python regular expression for retweets

i'm working on a regex that will extract retweet keywords and user names from tweets. here's an example, with a rather terrible regex to do the job: tweet='foobar RT@one, @two: @three barfoo' m=re.search(r'(RT|retweet|from|via)\b\W*@(\w+)\b\W*@(\w+)\b\W*@(\w+)\b\W*',tweet) m.groups() ('RT', 'one', 'two', 'three') what i'd like is to c...

Regular expression to catch letters beyond a-z

A normal regexp to allow letters only would be "[a-zA-Z]" but I'm from, Sweden so I would have to change that into "[a-zåäöA-ZÅÄÖ]". But suppose I don't know what letters are used in the alphabet. Is there a way to automatically know what chars are are valid in a given locale/language or should I just make a blacklist of chars that I (t...

How can I search and then replace a code snippet that includes some variables in TextMate?

I have a project that includes 49 folders, each one has a file called index.php All index.php files are almost the same except for one part that changes depending on the folder it is in. <?php include_once("/home/bgarch/public_html/galleryheader.html"); ?> <?php include_once("/home/bgarch/public_html/culture/loadscripts.html"); ?> </h...

Extract substring from string with Regex

Imagine that users are inserting strings in several computers. On one computer, the pattern in the configuration will extract some characters of that string, lets say position 4 to 5. On another computer, the extract pattern will return other characters, for instance, last 3 positions of the string. These configurations (the Regex patt...

mod_rewrite: Convert 'Folders' in URL Into Query Parameters

I want to be able to take a URL like: http://www.example.com/valOne/valTwo/valThree/valFour/valFive and convert it to: http://www.example.com/index.php?one=valOne&amp;two=valTwo&amp;three=valThree&amp;four=valFour&amp;five=valFive I really only need a few query parameters for my application so the Regular Expression could have thes...

Regular Expression : find a number near to a given String

I am trying to find a good way to capture a number that is at no more than N characters away from a given string. For example, if the String is "age" and N=4 have to find "Age 5" => 5 "My age is 10 and I my name is John" => 10 "My age is almost 5 and I my name is Mary" => null In the last case, the number is separated more than 4 cha...

ASP.Net FileUpload Control with Regex Validator postback problem

I'm trying to use a .Net FileUpload control along with a Regex Validator to limit filename to JPG, GIF, or PNG extensions. After postback, the filename is gone from the control (as expected), but this seems to cause the validator to fire and display its error text. Can anyone suggest a fix, or a better way? Thank you! ...

What's wrong with this regular expression?

This is almost certainly something really silly that I've overlooked but I'm stumped. The following C# style expression is supposed to match phones numbers (a limited subset of them, but this is just testing...): ^[0-9]{3}-[0-9]{3}-[0-9]{4}$ The search string is as follows: 978-454-0586\r\nother junk\r\nmore junk\r\nhttp://www.googl...

Regex that matches numeric with up to 2 decimal places

I am after a regex that will match numeric values with up to a user defined number of decimal places. Currently I have /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/ which will allow as many places as input but I would also like to sometimes allow 2 for currency or 4 or more for other input. The function I am building is var isNumeric...

Non regular context-free language and infinite regular sublanguages

I had a work for the university which basically said: "Demonstrates that the non-regular language L={0^n 1^n : n natural} had no infinite regular sublanguages." I demonstrated this by contradiction. I basically said that there is a language S which is a sublanguage of L and it is a regular language. Since the possible Regular expre...

javascript regexp, validating date problem

Hi there, I have some code for validating date below: function validateForm() { var errFound = 0; //var patt_date = new RegExp("^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))$"); var pat...

Regex to find all methods in a piece of code

Hi, I am trying to write a regex to match all the javascript method definitions in a constructor string. //These two should match this.myMethod_1 = function(test){ return "foo" }; //Standard this.myMethod_2 = function(test, test2){ return "foo" }; //Spaces before //All of therse should not //this.myMethod_3 = function(test){ return "f...

Wild card search in C#

I have a list of wild card based patter in a XML file. If the input string matches the pattern present in the XML doc, then a specific action would be taken. I did find the approach mentioned here http://www.codeproject.com/KB/recipes/wildcardtoregex.aspx but in that case, I need to create a RegEx object for every entry in the XML whic...