regex

"string" != "string"

Hi. I'm doing some kind of own templates system. I want to change <title>{site('title')}</title> Into function "site" execution with parameter "title". Here's private function replaceFunc($subject) { foreach($this->func as $t) { $args = explode(", ", preg_replace('/\{'.$t.'\(\'([a-zA-Z,]+)\'\)\}/', '$1', $subject)); ...

Shortening code

Nah, looks like it was hosting fault. Who can make this code shorter? private function replaceFunc($subject) { foreach($this->func as $t) { preg_match_all('/\{'.$t.'\([a-zA-Z,\']+\)\}/i', $subject, $res); for($j = 0; $j < sizeof($res[0]); $j++) { preg_match('/\([a-...

PHP regex delimiters, / vs. | vs. {} , what are the differences?

In the PHP manual of PCRE, http://us.php.net/manual/en/pcre.examples.php, it gives 4 examples of valid patterns: /<\/\w+>/ |(\d{3})-\d+|Sm /^(?i)php[34]/ {^\s+(\s+)?$} Seems that / , | or a pair of curly braces can use as delimiters, so is there any difference between them? ...

regex: match white-spaces that do not enclosed in []

For example, for this string, div.img-wrapper img[title="Hello world"] I want to match the first space but not the second space (which is enclosed in []). What is the regex? ...

Need a regex for .h or .cpp

I need a regex for finding all .h, .c, and .cpp files in a folder. Help? [no, this isn't homework, I just don't have time to learn regexes right now] ...

Regex: markdown-style link matching

I want to parse markdown style links, but I'm having some trouble matching the reference style ones. Like this one: [id]: http://example.com/ "Optional Title Here" My regex gets the id and the url, but not the title. Heres what I have: /\[([a-zA-Z0-9_-]+)\]: (\S+)\s?("".*?"")?/ I go through and add the references to a hashtable. th...

Check for a valid domain name in a string?

I am using python and would like a simple api or regex to check for a domain name's validity. By validity I am the syntactical validity and not whether the domain name actually exists on the Internet or not. ...

Phone Number validation using Regular Expression validation in c# 2008?

Hello Experts , I Want to validate the phone number in this format i.e +919981424199,+91231456789,.... I am using Asp.net +c#2008 for developing web site.for this i have used the Regular Expression validation control->property->Validation Expression="[0-9]+(,[0-9]+)*". But this accept the number as 919981424199,..... User may be enter ...

Regular expression, how to find all tags A which do not contain tag IMG inside it?

Hello, Let's suppose that we have such HTML code. We need to get all <a href=""></a> tags which DO NOT contain img tag inside it. <a href="http://domain1.com"&gt;&lt;span&gt;Here is link</span></a> <a href="http://domain2.com" title="">Hello</a> <a href="http://domain3.com" title=""><img src="" /></a> <a href="http://domain4" title="">...

Allow only [a-z][A-Z][0-9] in string using PHP

How can I get a string that only contains a to z, A to Z, 0 to 9 and some symbols? ...

Switch statement for string matching in JavaScript

How do I write a swtich for the following conditional? If the url contains "foo", then settings.base_url is "bar". The following is achieving the effect required but I've a feeling this would be more manageable in a switch: var doc_location = document.location.href; var url_strip = new RegExp("http:\/\/.*\/"); var base_url = url_strip...

Help with regex pulling XML data from response body in PHP

I am working on a project that pulls data from JMS queue using PHP and Zend Framework. The HTTP client response is below. All I need is the XML string. I came up with /(.*)<\/RequestDetails>/gs which tests ok on http://gskinner.com/RegExr/ but the preg_match call is returning an empty matches array. I'm going to continue to hunt ar...

preg_match , regexp , php , ignore white spaces and new lines

I'm trying to extract richard123 using php preg_replace but there are a lot of white spaces and new lines and I think because of that my regexp doesn't work . The html can be seen here : http://pastebin.com/embed_iframe.php?i=vuD3z9ij My current preg_match is : $find = "/< tr bgcolor=\"F0F0F0\" valign=\"middle\">< td align=\"left\">< ...

Why was this regex calling substcont an excessive number of times?

This is more out of curiosity than anything else, as I'm failing to find any useful info on Google about this function (CORE::substcont) In profiling and optimising some old, slow, XML parsing code I've found that the following regex is calling substcont 31 times for each time the line is executed, and taking a huge amount of time: ...

Trying to replace contents of a Div, with no luck

Ive tried to use the Dom model with no bloody luck, getElementByID just doesnt work for me. I loathe to resort to a regex but not sure what else to do. The idea is to replace a <div id="content_div"> all sorts </div> with a new <div id="content_div"> NEW ALL SORTS HERE </div> and keep anything that was before or after it in the string....

Filtering out emoticons using sed

Hello, I have a grep expression using cygwin grep on Win. grep -a "\\,,/\|\\m/\|\\m/\\>\.</\\m/\|:u" all_fbs.txt > rockon_fbs.txt Once I identify the emoticon class, however, I want to strip them out of the data. However, the same regexp above within a sed results in a syntax error (yes, I realize I could use /d instead of //g, but t...

Regular expression for browser Url

I am new to JavaScript i need a regular expression which allows both of this forms for example : http://www.google.com www.google.com ...

How to remove words based on a word count

Here is what I'm trying to accomplish. I have an object coming back from the database with a string description. This description can be up to 1000 characters long, but we only want to display a short view of this. So I coded up the following, but I'm having trouble in actually removing the number of words after the regular expression ...

How do I test against a large number of regular expressions quickly and know which one matched?

I'm writing a program in .net where the user may provide a large number of regular expressions. For a given string, I need to figure out which regular expression matches that string (if more than one matches, I just need the first one that matches). However, if there are a large number of regular expressions this operation can take a v...

Python - Strange Behavior in re.sub

Here's the code I'm running: import re FIND_TERM = r'C:\\Program Files\\Microsoft SQL Server\\90\\DTS\\Binn\\DTExec\.exe' rfind_term = re.compile(FIND_TERM,re.I) REPLACE_TERM = 'C:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\DTExec.exe' test = r'something C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTExec.exe somethin...