regex

how do I make vim highlight any { not followed by either a C++ style comment, or two newlines?

I would like to create a match pattern for any opening brace that does not follow one of these patterns: A: {\n\n B: {\s*\/\/.*\n\(\s*\/\/.*\)\?\n The more general problem is highlighting violations of a coding spec at work, which enforces a blank line following { Clarification: I'm looking for this to catch code like the followin...

Python Regular Expression Match All 5 Digit Numbers but None Larger

I'm attempting to string match 5-digit coupon codes spread throughout a HTML web page. For example, 53232, 21032, 40021 etc... I can handle the simpler case of any string of 5 digits with [0-9]{5}, though this also matches 6, 7, 8... n digit numbers. Can someone please suggest how I would modify this regular expression to match only 5 d...

Asp.net URL rewriting (regular Expressions)

Can anybody help me regarding URL rewriting. As I have the URLs like http://somedomain.com/products.aspx?id=1 and i want to rewrite this like somedomain.com/productname and rest of the URLs on the domain work as they are provided. like somedomain.com/forums/categories.aspx I don't want to rewrite these other URLs Regards, John ...

Regex: I want this AND that AND that... in any order.

I'm not even sure if this is possible or not, but here's what I'd like. String: "NS306 FEBRUARY 20078/9/201013B1-9-1Low31 AUGUST 19870" I have a text box where I type in the search parameters and they are space delimited. Because of this, I want to return a match is string1 is in the string and then string2 is in the string, OR strin...

PHP Regular Expression to match define() function

Hi people I'm doing a translation of php script and want to gain some time by doing some automatization The file contains very large number of lines like these define('LNG_NewsletterNameIsNotValid', 'Email Campaign name is not Valid'); define('LNG_UnableToCreateNewsletter', 'Unable to create an Campaña de Email'); define('LNG_HLP_Newsle...

Regular Expression Help

I am learning regular expressions and I am trying find this string day1otlk_XXXX.gif where the 4 X's will be 3 to 4 random digits. This is what I have so far am I close? qr/day1otlk_\d++\.gif/i ...

Python regex, matching pattern over multiple lines.. why isn't this working?

I know that for parsing I should ideally remove all spaces and linebreaks but I was just doing this as a quick fix for something I was trying and I can't figure out why its not working.. I have wrapped different areas of text in my document with the wrappers like "####1" and am trying to parse based on this but its just not working no ma...

RegEx for three letters and two numbers

Hi! Two quick questions: What would be a RegEx string for three letters and two numbers? I.E "LET 12" ? And so I don't bother you guys in the future, would you happen to know any good RegEx resources/tools? EDIT: There will be space before and after the 'LET 12', sorry I forgot to mention that! :) ...

.NET regex captures not in expected order

In .NET, regex is not organizing captures as I would expect. (I won't call this a bug, because obviously someone intended it. However, it's not how I'd expect it to work nor do I find it helpful.) This regex is for recipe ingredients (simplified for sake of example): (?<measurement> # begin group \s* # o...

regex pattern to match alternating subpatterns

Hi, I'm trying to devise a regex pattern (in PHP) which will allow for any alternation of two subpatterns. So if pattern A matches a group of three letters, and B matches a group of 2 numerals, all of these would be OK: aaa aaa66bbb 66 67abc 12abc34def56ghi78jkl I don't mind which subpattern starts or ends the sequence, just that af...

Capturing regex compilation errors

I am trying to set up a service similar to rubular, but with PHP as the language using the preg family of functions. It will take an input regex, a test string, and run preg_match(). How can I find out if a compilation error has occurred (eg: invalid regex), and if that is the case, what was the error? Normally it will throw warnings l...

find and replace double newlines with perl?

I'm cleaning up some web pages that for some reason have about 8 line breaks between tags. I wanted to remove most of them, and I tried this perl -pi -w -e "s/\n\n//g" *.html But no luck. For good measure, I tried perl -pi -w -e "s/\n//g" *.html and it did remove all my line breaks. What am I doing wrong? edit I also tried \r\n\r\...

Perl regex parse forward only; not end-to-start

Parsing HTML with regex is a bad idea, but it seems suitable for this situation. Description: Given a .html file, I must parse the internal links, extract the indent level, text of the link and the page number it resides on to an external .txt file which is then passed on to someone else. So given this sample HTML: <TR valign="bottom"...

Notepad++ strip bbcode color statements

Here is what my text file looks like: [img]asset:/052cf103006dc0a1aee06067b12b2153-40[/img] Adrik Thorgrim: [color=#000000]done for the night then?[/color] GM: [color=#000000]Yes[/color] [img]asset:/052cf103006dc0a1aee06067b12b2153-40[/img] Adrik Thorgrim: [color=#000000]I would prolly plan on altruis notshowing up[/color] [img]asse...

IE and Firefox regular expression question

Why the following pattern in IE and Firefox matches result different? var str = 'a,b,c , d, e ,f'; var matches = str.split(/(\s+)?,(\s+)?/); alert(matches); IE: a,b,c,d,e,f firefox: a,,,b,,,c, , ,d,, ,e, ,,f how to match like IE result? please answer me :( ie8 and firefox v3.6.8 ...

Regular expression to remove the pound sign from a string, if exists

I want to remove the pound sign (#) from a hex string if it exists. I tried the following code... $str = "#F16AD3"; //Match the pound sign in the beginning if (preg_match("/^\#/", $str)) { //If it's there, remove it preg_replace('/^\#/', '', $str); }; print $str; ..but it didn't work. It prints out "#F16AD3". Any ideas? ...

preg_match a part of an HTML file : find X and (maybe X or not) until the end of HTML file

Hi to all, This is driving me nuts! A little piece of code that I can't seem to debug :( Basically I have an HTML file in a string and I want to find X inside until another X (same value) IF there is another one, if there isn't, then grab X until end of file. The code that doesn't work: $contents = "< div id="main" class="clearfix"> ...

How to replace new lines by regular expressions

Hello, can you help me with replacing in PHP. I dont know how to set any quantity of new lines with regex. $var = "<p>some text</p><p>another text</p><p>more text</p>"; $search = array("</p>\s<p>"); $replace = array("</p><p>"); $var = str_replace($search,$replace,$var); What i need, is to remove every new line (\n), not <br/>, beetwe...

Matching a specific Tag using Regular Expression

I have the following Tags : <a href="News_ViewStory.asp?NewsID=5215"> Some Text </a> <a href="News_ViewStory.asp?NewsID=5216"> Some Text </a> <a href="News_ViewStory.asp?NewsID=5217"> Some Text </a> I want to match the begining of the Tag ' <a href="News_ViewStory.asp?NewsID=5215"> <a href="News_ViewStory.asp?NewsID=5216"> <a href="...

get the content of matched element

i have a string $str = "this is [start] my string [end] at this moment"; i need to get the content within [start] and [end]. when i use $result = preg_match('/\[start\].+\[end\]/',$str, $m); it mutches [start] my string [end], but i need to get only my string(without spaces). sure i can make another preg_replace and delete the...