regex

How can I get RegEx.Split to extract a series of numbers containing decimal points from a string?

This sort of example for extracting integers from a string is common: string input = "10 blah 20 30 nonsense 40 50"; string[] numbers = System.Text.RegularExpressions.Regex.Split(input, @"^[\d]"); But how can I account for numbers with a decimal point? e.g. string input = "10 blah 20 30 nonsense 40.5 50" used with the above regul...

How to rewrite url containing plus and special chracters?

We've got some incoming URLs that needs to be redirected, but we are having trouble with URLs that contains pluses (+). For example any incoming URL must be redirected to the Homepage of the new site: /eng/news/2005+01+01.htm Should be redirected to to the home page of the new site /en/ Using UrlRewriter.net we've set up a r...

Regex: why doesn't [01-12] range work as expected?

Hi, I'm trying to use the range pattern [01-12] in regex to match two digit mm, but this doesn't work as expected. Please advise, thanks. ...

count quotes in a string that do not have a backslash before them.

Hey I'm trying to use a regex to count the number of quotes in a string that are not preceded by a backslash.. for example the following string: "\"Some text "\"Some \"text The code I have was previously using String#count('"') obviously this is not good enough When I count the quotes on both these examples I need the result only to...

Javascript Date Regex eg. 2010-06-03

i want a function that validates dates of the format in the title. what is wrong with my function? function validateDate(date) { var pattern = new RegExp("^\d{4}-\d{2}-\d{2}$"); if (pattern.test(date)) return true; return false; } thanks! ...

how to excluded directory from nginx conf?

in nginx conf file,i use: location ~ \.jsp { proxy_pass http://127.0.0.1:86; } to parse my jsp file, now,i want excluded directory /upload/ this directory is user upload file directory ,don't need parse JSP file.(http://xxx.com/upload/) how to change my location ~ \.jsp { ? i need parse JSP *.jsp but excluded /upload/ and it...

trying to show definitions for words that are in a glossary

Hi, I'm trying to use regex to parse some plain text and add a definition from a glossary to any words that match it. I'm doing it like this: for ( $i = 0; $i < count($terms); $i++ ) { $search = '|(?<=\b)('.preg_quote($terms[$i]['title']).')(?=\b)|i'; $replace = '<a class="tt2" rel="tooltip" title="'.$terms[$i]['pageBody'].'">...

How to get all rows that contain characters others than [a-zA-Z] in MySQL

I would like to ask if there is a possible way to select all rows from a table where the content of a column (varchar(255)) may contain characters others than standard english (a-zA-Z) or characters from different languages like Greek, French. For example if the table contains the following data: -- ID, Address -- | 1, "Test1" | | ...

PHP Template Engine

How can I improve the script below to be able to add global template parts such as start and end of the page? <?php class simpleTemplate { var $variables; var $variables_callback; var $contents; var $preg; var $regexps; // Constructor, initialize default variables functio...

Trying to match '#' in a text.

I'm trying to match a "#" followed by letters if and only if it's preceded by newline, whitespace or is the first character in a string. The first two I've done, but I'm having a hard time matching if it's the first character in a string. I'm trying to find a use for '\A', but it doesn't work to just add it to the class containing newlin...

extract stylesheets via regex

Yes, I know, I know, parsing HTML with regular expressions is very bad. But I am working with legacy code that is supposed to extract all link and style elements from a html page. I would change it and use the dom extension instead, but after the regex there is a huge code block which relies on the way preg_match_all returns the matched ...

python: how to find \r\n\r\n in one single search

I have to split the file content based on first occurrence of \r\n\r\n I need flexibility such a way that the lines can just ends with \r\n\r\n or \n\n. How to split the text? Example added: \===================FILE BEGIN========================================== name: about title: About publish: True order: -1 \r\n \r\n examp...

What kind of regex would I use to match this?

I have several strings which look like the following: <some_text> TAG[<some_text>@11.22.33.44] <some_text> I want to get the ip_address and only the ip_address from this line. (For the sake of this example, assume that the ip address will always be in this format xx.xx.xx.xx) Edit: I'm afraid I wasn't clear. The strings will look s...

Need regex help with 2 URL rewrite cases (for SQUID server using SQUIRM)

case 1: IN: example.com?p1=val1&p2=val2&p3=val3 OUT: example2.com?p1=val1&p2=val2&p3=val3&p4=val4 -- p4=val4 was added to the end, the rest of the parameters were preserved case 2: IN: example.com?p1=val1&p4=badvalue OUT: example2.com?p1=val1&p4=goodvalue -- the value of p4 was changed, so we need to scan for the existence of the ...

rails: convert a string with regex and write to database

I have an application that accepts an address and writes it to the db. I then want to take that address and convert it to something I can send through Google Maps, so I need to replace all the spaces with "+" symbols. I understand how to do that with a regex: address.gsub(/\s/, "+") And can create a variable that does it, voila. But I...

Regular expression help in PHP

I'm currently trying to learn regular expressions with some simple "real world" examples. Take in consideration the following string: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9.2a1pre) Gecko I want to find the RV value (1.9.2a1pre). I need to apply the following rules: RV: can be in any case (RV, rv, rV, Rv...). RV...

How can I remove the caret(^) from a string using a RegExp in Javascript?

For some reason, I can't seem to find a good answer for this one. I have been trying to escape out the caret (\^), and to use the hex, octal, and other codes for the character using \xdd, \dddd, etc... But my replace regexp won't replace the caret (^) with anything. It seems to simply break the expression. Here is the code I am using:...

Unexpected javascript behaviour issue

I wrote this validation method but am having issues with it. function validate_password(pwd) { var score = 0; // Min length is 8 if (pwd.length<8) return false; // Is lower present? if (/[a-z]/g.test(pwd)) { console.log('a-z test on "'+pwd+'":' + /[a-z]+/g.test(pwd)); score++; } ...

Why is this regex not causing an error in Javascript?

Hi. I'm a bit confused about different regex formats. The following methods are causing an error. function validateDate(str) { var expr = /^((((0?[1-9]|[12]\d|3[01])[\/](0?[13578]|1[02])[\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\/](0?[13456789]|1[012])[\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\/]0?2[\/]((1[6-9]...

Regex to split text containing tokens

If I have a string such as "abcdef{123}ghi{456}kl", I want to create a regex that will give me all the parts separated as follows: abcdef {123} ghi {456} kl I am using this code, but can't figure out what the expression should be: System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex("expression"); fore...