regex

Using variables in regex for string search in Ruby

I'm trying to search a string for match on an array of words. I tested the code by specifying a word and also an input and it correctly finds it, but for some reason I can't get it to work in general. I checked that the input is a String and the words are extracted from the list as well. Any help on this would be appreciated. Thanks...

How to write this regular expression in VB.net?

My coworker needs me to write him a regular expression for his vb.net app. I do not know vb and he does not know regex. The regex he needs is: /.*web id: ?(\d+).*/i Basically he needs to search a string for something like "web id: 345" or "web id:2534" and retrieve the ID. He took what I gave him above and was able to put this toge...

How do I catch an invalid preg_match pattern?

I am writing a PHP script that accepts a regular expression pattern from the user which is used by preg_match(). How can I check that the pattern is valid? ...

Hard time with escape character

I need to strip out a few invalid characters from a string and wrote the following code part of a StringUtil library: public static String removeBlockedCharacters(String data) { if (data==null) { return data; } return data.replaceAll("(?i)[<|>|\u003C|\u003E]", ""); } I have a test file illegalCharacter.txt with one l...

Regex replace to change the order of words in a sentence

If I have a string like this: "word1 'word2' word3" is it possible to use a regex replace to change the string to this: "word1 word3 'word2'" I know what word1 and word3 will be, but do not know what word2 will be, but it will always be in single quotes. ...

How to validate a complete and valid url using Regex

I have a URL validation method which works pretty well except that this url passes: "http://". I would like to ensure that the user has entered a complete url like: "http://www.stackoverflow.com". Here is the pattern I'm currently using: "^(https?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //user@ + @"(([0-9]{1,...

Help me rewrite this regex to not match tags with attributes?

========================================================================= EDIT: I'm using node.js, so I don't have access to the DOM, and parsing with an HTML parser is not an option (it's not efficient enough to justify parsing through such a small amount of text) =======================================================================...

string replace using a List<string>

I have a List of words I want to ignore like this one : public List<String> ignoreList = new List<String>() { "North", "South", "East", "West" }; For a given string, say "14th Avenue North" I want to be able to remove the "North" part, so basically a function that would r...

Why does this regex have 3 matches, not 5?

I wrote a pretty simple preg_match_all file in PHP: $fileName = 'A_DATED_FILE_091410.txt'; $matches = array(); preg_match_all('/[0-9][0-9]/',$fileName,$matches); print_r($matches); My Expected Output: $matches = array( [0] => array( [0] => 09, [1] => 91, [2] => 14, [3] => 41, [4] => 10 ...

Python Regular Expression Question

Say I have text 'C:\somedir\test.log' and I want to replace 'somedir' with 'somedir\logs'. So I want to go from 'C:\somedir\test.log' to 'C:\somedir\logs\test.log' How do I do this using the re library and re.sub? I've tried this so far: find = r'(C:\\somedir)\\.*?\.log' repl = r'C:\\somedir\\logs' print re.sub(find,repl,r'random tex...

How to match up to second letter using regex?

How would I match "22A00" in the following string: "22A00B20A" using a regular expression? ...

MySQL REGEXP for numbers that begin with ..

Hi guys. I need to write a query using MYSQL REGEXP that will find me rows that have a certain column begin with 11 or 12 or etc. I know I can use LIKE or LEFT(####,2) but would like to use the REGEXP option. My data is stored as 110001, 122122, 130013a and etc. EDIT 1: To make it more clear, I would like to express SELECT * FROM ...

Javascript Invalid quantifier in regex

The regex is constructed on the fly, but I've output it to firebug: (.{1,38})(+|$\n?) the error is invalid quantifier +|$\n?) I don't even know what invalid quantifier means! I really feel like I'm going to get the "Show us something relevant" answer, but I'm not sure where to start. The actual code is: var re = top.RegExp; var ...

parsing out in javascript

I want to check a string and if it has no <br /> starting then I don't wanna do any thing for example mysqtinr = 23435-acs as you can see no <br /> starting but if the string has the following then I wanna parse it out myString = <br /> some text goes here <b> Some other things </b>: just more test <b> http://website/index.php </b> on...

Regex: does a SQL statement include a WHERE clause?

I need a regex that will determine if a given SQL statement has a WHERE clause. My problem is that the passed SQL statements will most likely be complex, so I can not rely on just the existence of the word WHERE in the statement. For example this should match SELECT Contacts.ID , CASE WHEN (Contacts.Firstname IS NULL) THEN '' ...

Regular Expression validator with file upload control (asp.net) does not work in FireFox

I am using Regular Expression validator with file upload (Asp.Net) control in-order to restrict the files uploaded. My regular expression is as follows: ^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.wmv|.avi|.mpeg|.MPEG|.mp4|.MP4|.flv|.f4v)$ It gives error message of the validator even after uploading the right file in Firefox. But it ...

Anyone see anything wrong with my regex for port numbers?

I made a regex for port numbers (before you say this is stupid, its going into a bigger regex for URL's which is much harder than it sounds). My coworker said this is really bad and isnt going to catch everything. I told him no way! This thing catches everything from 0 to 65535 and NOTHING ELSE. Someone confirm this for me or my coworke...

PHP Simple CSS string parser

I need to parse some CSS code like: color: black; font-family:"Courier New"; background:url('test.png'); color: red; --crap; Into: array ( 'color'=>'red', 'font-family'=>'"Courier New"', 'background'=>'url(\'test.png\')', '--crap'=>'' ) I need to do this via PHP. I can see this done easily via regexp (well, easy to...

preg_match custom pattern

I'm trying to figure out how to make custom pattern to use with preg_match / preg_match_all. I need to find [A-Z]{3}[a-z]{1}[A-Z]{3}, that would be for an example AREfGER. 3 uppercase, 1 lowercase and 3 uppercase. anyone know how to make a pattern for this? ...

regex that can distinguish PHP tags contained in HTML tags

I need a javascript regex that can distinguish between PHP tags in HTML tags and PHP tags outside of HTML tags. e.g. <input type="text" <? print '1'; ?> value="<? print '2'; ?>"> <? print '3';?> So I need a regex to pull out: <? print '1'; ?> and <? print '2'; ?> And another regex to pull out: <? print '3';?> At the moment I h...