regex

adding characters at the start and end of each line in a file

What is the best way to add some characters at the start and end of each line? something like quotes etc? Can it be done using Vim, or some other way? ...

What is a cross platform regex for removal of line breaks?

I am sure this has been asked before, but I cannot find it. Basically, assuming you are parsing a text file of unknown origin and want to replace line breaks with some other delimiter, is this the best regex, or is there another? (\r\n)|(\n)|(\r) ...

Use Replace Method In Linq-Sql Query

I used RegEx to remove HTML TAGS within LINQ-SQL query but the following error has thrown: Method 'System.String Replace(System.String, System.String, System.String)' is not supported for execution as SQL. Help helpDBSession = new Help(); IEnumerable<Article> articles = null; if (lang.ToLower() == "en") ...

PHP regex for matching double and/or single quoted strings within in a string.

Hello, I'm working on a template class and I've an issue when trying to parse out a list of quoted strings from a string argument list. Take for example the string: $string = 'VAR_SELECTED, \'Hello m\'lady\', "null"'; I'm having a problem coming up with a regex that extracts the string "Hello m'lady" and "null". The closest I have go...

Match only backticks not inside a <code> block with Regex.

First things first. I know how to parse XML/HTML with simplexml, and I know all the arguments against using RegEx to parse it. This question is for the sake of knowledge. What needs to happen In a block of text let's say we have the following line of text: The query you need to use is <code>SELECT `post_name` FROM table WHERE id= $id...

Regular Expression PHP Help with if not equal to

I am trying to use regular expressions to make my inventory upload script a little better. I sell clothing and accessories. In my inventory file I have a field called ProductDepartment which is a combination of gender/item type. I have a MySQL table for gender with the following values: Mens = 1 Womens = 2 Unisex = 3 Departments in...

PHP How to remove numbers like [3][2][4] from string using php

I have a text string that contain some references numbers like [3][2][4] or [1] or [5][7] can you please help me removing all numbers between brackets ex. [4] from that string using regular expressions Regex ? Thanks ...

Regular Expressions in OCaml

Hello, I want to use regexps in OCaml and it seems that Str module provides these functionalities. So I tried with a simple program: open Str let regx = regexp "." but it gives me the following error File "lol.ml", line 1, characters 0-1: Error: Error while linking lol.cmo: Reference to undefined global `Str' As if module i...

Textmate snippet to add file name and path in comment?

I'm using an existing snippet in Textmate to reduce the repetition of creating controllers and models. The snippet works great, but I'd love to add a comment to the end of each file. For example: /* End of file filename.php */ /* Location: ./system/application/controllers/filename.php */ The first line is easy: /* End of file ${TM_...

Regex replaces everything that matches any character

a[b].innerHTML=a[b].innerHTML.replace(RegExp('['+bbc[c][0]+']','ig'),bbc[c][1]) This is basically what I'm working with. It's wrapped in two loops so that should explain why it looks like what it does. Basically I want to replace something that matches '['+variable from an array+']'. I'm making a BBCode script for a free forum and no d...

How to extract IP addresses from a text file using Perl?

How do I extract just the IP addresses from a text file which has an IP address per line? I would like to extract the IPs and then list the IP addresses in a separate file. The text file that contains the IPs are in the following format: Host somehost.com (192.168.1.1) is up (0.20s latency). Host 10.1.0.0 is up (0.21s latency). Host 17...

Non-terminating RegExp.exec in Rhino

I have the following JavaScript program saved in a file pre.js: var pre = readFile("method-help.html"); RegExp.multiline = true; print(/<pre>((?:.|\s)+)<\/pre>/.exec(pre)[1]); The contents of method-help.html is simply the page at http://api.stackoverflow.com/1.0/help/method?method=answers/%7bid%7d. What I'm trying to do is get the J...

How to find the suspicious statement, like "Name = Name;" in C# by Regex?

My C# code has a lot of statement like "this.Name=...". In order to make my code neat, I let the text editor to replace all "this." to nothing. The code still worked. But later I fund it caused me a lot of new troubles for I wrote some statements like: this.Name = Name; // the second Name is a parameter. After the replacement, it beca...

Any character including newline - Java Regex

I thought it may be [.\n]+ but that doesn't seem to work? ...

preg_match: nothing to repeat / no match

hi there, I am using this: if(!preg_match('/^+[0-9]$/', '+1234567')) and am getting: Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 any ideas why? update: Now using this: if(!preg_match('/^\+[0-9]$/', '+1234567')) and am getting no match. any ideas why? ...

Replace href in PHP

Hello! I'm trying to transform this: http://link_brochure/1/2 OR link_brochure/1/2 into this: class="show-brochure" href="http://localhost/main/brochure/1/2" But I'm a rookie when it comes about regular expressions... Any ideas? Thanks! ...

URLRewrite IIS 7

Hi, I am trying to perform a simple URLRewriting. if you visit azamsharp.com it will take to some folder browsing structure it should go to http://www.azamsharp.com/AzamSharpWebApps/Default.aspx. I don't want to see the AzamSharpWebApps in the URL: Here is the URL Rewrite I am using: <system.webServer> <rewrite> <rules> ...

Need a simple Regular Expression

Hi Guys I don't understand Regular Expressions that well. I need an expression that will only accept: numbers normal letters (no special characters) - spaces are not allowed either. Example: The regular expression should match: this-is-quite-alright It should not match this -is/not,soålright ...

What's a portable and lightweight C/C++ regular expression library?

Possible Duplicate: Lightweight and portable regex library for C/C++? I'm looking for a C++ (C is acceptable, too) library for matching regular expressions. The library should satisfy these requirements: Can be built on Windows (MSVC 7 and newer) Can be built on Linux (g++ 3.4 and newer). Has no external dependencies; nothin...

Regex to match "{number}"

I need to replace "{Z}" with "test(Z)" where Z is always an unsigned integer using PHP and regular expressions (unless there's a faster way?). $code='{45} == {2}->val() - {5}->val()'; // apply regex to $code echo $code; // writes: test(45) == test(2)->val() - test(5)->val() The tricky part is that it needs to be done in the best manne...