regex

VIM Relace all <a ...> and </a>?

Sorry this might be a simple question, but I could not figure it out. What I need is to filter out all the <a href...> and </a> strings out from a html text. Not sure what regular expression I should use? I tried the following search without any luck: /<\shref^(>)> what I mean here is to search for any string starting with "< href" an...

regex to match spaces and apostrophes

Hi i need a regex that matches all instances of any character that is not a-z (space and things like apostrophes need to be selected). Sorry for the noob factor. thanks! //novice ...

RegEx: Smallest possible match

How do I tell RegEx (.NET version) to get the smallest valid match instead of the largest? ...

Replace serial in zone files with sed

Hi, I need to replace the serials in my zone files, and I thought the easiest would be to use sed to change this. I have the following line to test. @ IN SOA ns1.domain.com. webdev.domain.com. ( 2006080401 ; serial 8H ; refresh 2H ; retry 1W ; expire 4h) ; minimum ttl NS ns1.domain.com. NS ns...

addslashes() for preg_replace() and co.?

How can I escape incoming data so I can use it as a pattern in preg_replace() and consorts? For example, I need to match against this string: /vorschau/ Obviously, I need to escape the "v" or I will get an error. I can't find anything in the documentation. Is there some sort of addslashes() for this, or a workaround within the expres...

[A-Z]{2,4} not limiting to between 2 & 4 characters

PCRE: /\A[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[a-z]{2,4}|museum|travel)\z/i POSIX: /^[A-Z0-9_\.%\+\-]+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i This regex is correct in every way for my needs except that it allows emails such as [email protected]. It says these are a match. If I'm not mistaken, doesn't the {2,4} after [A-Z] mean th...

regular expression for French characters

Hi, I need a function or a regular expression to validate strings which contain alpha characters (including French ones), minus sign (-), dot (.) and space (excluding everything else) Thanks ...

Allow param containing slashes in Zend_Controller_Router_Route_Regex

This is my code: $route = new Zend_Controller_Router_Route_Regex('download/([^/]+)(/([^/]+))?/(\d+)/(\d+)', array('controller' => 'download', 'action' => 'load'), array(1 => 'name', 3 => 'or_name'...

VS2008 C# : Regular expression and identifying certain words

I would like to use Regular expression to identify certain words in a string. For example: "bla bla bla | First Name = John Doe | City = Denver | bla bla bla | State = CA | bla bla bla" In the above string, which is | delimited for words, I want to parse out the content of First Name, City, and State and store them some where like...

vim search-replace question

Hi, I have a few trace lines in my file of the form M_TRACE(EV_TRACE_LEVEL_DEBUG, "some trace"); I want to convert those into M_TRACE(EV_TRACE_LEVEL_DEBUG, "%s: some trace", __FUNCTION__); However I have already a few traces which display the function name also. To make the conversion i am using the following command :%g/M_TRACE/...

How to specify to Regex (in a LINQ Query) to only compare the start of a string?

I have the following code: string filterTerm = txtDocFilterTerm.Text.ToLower(); var regEx = new Regex(filterTerm); //griQualifiedDocs is a grid //storage.QualifiedDocs is the master/original collection griQualifiedDocs.ItemsSource = storage.QualifiedDocs .Wher...

Single RegEx to parse this log format?

Hello, I am trying to wrap my head around the feasability of parsing a log file with a single RegEx in .NET What is making it difficult is the log file has items that can (but don't always) span multiple lines and that each log file may actually contain multiple 'logs'. Example format: log: event 1 event 2 additional in...

How to mimic StackOverflow Auto-Link Behavior

With PHP how can I mimic the auto-link behavior of StackOverflow (which BTW is awesomely cool)? For instance, the following URL: http://www.stackoverflow.com/questions/1925455/how-to-mimic-stackoverflow-auto-link-behavior Is converted into this: <a title="how to mimic stackoverflow auto link behavior" rel="nofollow" href="http://...

IIS7 URL Rewrite Mod causes unwanted effects

This might be more a a regex question, but it is holding up our release. I'm unable to come up with a clever solution. Basically, we want to rewrite www.oursite.com/Games.aspx?g=classic&m=etc to www.oursite.com/classic/?m=etc The problem is that the rule itself (at least as generated by the URL Rewrite mod for IIS7) looks like this: <...

Is this possible with regular expressions?

Something like this: /[abcd]/[efgh]/ The idea is that a will get replaced with e, b with f, c with g and so on. Ideally, this should be language independent. If that isn't possible, I have an alternate solution (because this regex is generated by some code, I can make one for each of the possible replacements). ...

Why Group.Value always the last matched group string?

Recently, I found one C# Regex API really annoying. I have regular expression "(([0-9]+)|([a-z]+))+". I want to find all matched string. The code is like below. string regularExp = "(([0-9]+)|([a-z]+))+"; string str = "abc123xyz456defFOO"; Match match = Regex.Match(str, regularExp, RegexOptions.None); i...

Capture multiple lines using Regular Expression (.Net)

I am trying to write a regular expression that can parse the text between < p >< /p > tags. There will be up to 3 lines of text in a row. I thought this might be possible using the (?= search ahead feature. The code that I am currently using to get one line is as follows. <p>([^']*?)<[/]p Is it possible to have one regular expressi...

A positive number from 1 to 2^31 -1 in regex

Hi, I got the following regex that almost does the work but does not exclude zero ...How to do that? ^(\d|\d{1,9}|1\d{1,9}|20\d{8}|213\d{7}|2146\d{6}|21473\d{5}|214747\d{4}|2147482\d{3}|21474835\d{2}|214748364[0-7])$ Also can anybody explain a bit how this works? ...

RegEx for extracting number from a string

I have a bunch of files in a directory, mostly labled something like... PO1000000100.doc or .pdf or .txt Some of them are PurchaseOrderPO1000000109.pdf What i need to do is extract the PO1000000109 part of it. So basically PO with 10 numbers after it... How can I do this with a regex? (What i'll do is a foreach loop on the files in th...

Regex-problem in C#

I'm trying to write a regular expression that will check so a given string is a "valid" name. The name-strings are retrieved from a database and then checked to see if they contain weird chars. (Since this is for a Swedish system, I still have to include a few weird chars that are common in Swedish names. ;) ) The problem is that this f...