regex

Fast Javascript String Replacement

Hey there geniuses of SO! This is for an autocomplete plugin that needs to accept data as an array of arrays and convert it using a format string (or regex). The format string could be any format. var dataArray = [ ["data1-1", "data1-2", "data1-3"], ["data2-1", "data2-2", "data2-3"],... ]; var format = "<li>{0} <br /> -- <small> {1}, {...

How do I match the last character in an arbitrary string using C# Regexes?

The obvious attempt is: Regex.Replace(input, @".$", "X", RegexOptions.Singleline); This doesn't always work though. Consider the string \r\n\r\n - the above produces the surprising result of \r\nXX. One might expect from reading MSDN (under Multiline) that $ should match just at the end of the entire string, but apparently $ actually ...

Regular Expression: Split English and Non-English words with Comma?

Is there any regular expression pattern to change this string This is a mix string of üößñ and English. üößñ üößñ are Unicode words. to this? This is a mix string of, üößñ, and English., üößñ üößñ, are Unicode words. Actually, I want to split English words and non-English words with comma. Thanks. ...

Using regular expression to extract full words from text

I have been working with parsing data, I got a string like: "Scottish Premier League (click here to open|close this coupon)" I would like to extract "Scottish Premier League" with Scottish Matching Group 1 and Premier League Matching Group 2, using regular expression. Please show me the way to do that using regular expression. Match...

Regular Expression Match Without Final Character

I'm trying to match any requests for a url that do not have a folder character (/) or end with an extension (.aspx). I can ignore querystring values and fragments in the regular expression for now. So far I have the following. ^([\w-/]+)(?!\.aspx|/)$ However, if I run this expression it selected the final / in the group which I don't ...

Regex for non-alphabets and non-numerals

Please provide a solution to write a regular expression as following in C#.NET: I would require a RegEx for Non-Alphabets(a to z;A to Z) and Non-Numerals(0 to 9). Mean to say as reverse way for getting regular expression other than alphabets and otherthan numerals(0 to 9). Kindly suggest the solution for the same. ...

To comment out matches in Vim - independent on comment leader?

Hi! I want to comment out lines in some code I have. I have different kinds of codes, and they use different comment leaders. E.g. in latex: '%', in Fortran 90: '!' and in python: '#'. I want to do a substitute command that looks something like this: :g/<search-string>/s/^/<add-comment-leader-here>/ If this is possible, I could al...

Is there any good book or website where I can learn php regular expressions?

Any recommendations, as I need to learn regular expressions to search for specific string and replace using specific operators. I have looked at the php functions such as preg_match && preg_replace and understood how they work but all I need is to be more familiar with the operators for expressions. Thanks. ...

How to validate domain name in PHP?

Is it possible without using regular expression? For example, I want to check that a string is a valid domain: domain-name abcd example Are valid domains. These are invalid of course: domaia@name ab$%cd And so on. So basically it should start with an alphanumeric character, then there may be more alnum characters plus also a hyphe...

How do I find all expression "variable = variable;" in the Visual Studio 2008?

I want to find all expression variable = variable; in my source files. I use Visual Studio 2008. The variable is any variable, for example x, i, k123, incr15. Samples: x = x; // Should find x = y; // No match ss12 = ss12; // Should find ss12 = ss12 + 1; // No match ...

Regex challenge: can't use '^'

Long story short, I'm working with a library with a bug that causes a crash if I use a regex that has a caret after a bracket (for example, the regex [^a]). The bug is being worked on, and switching libraries is not an easy option, and I'd like to be able to continue work between now and when the bug is fixed. Thus, I need to express th...

MySQL Regex Replace

Does anybody know how I could have, in a MySQL query, the same behaviour as the Regex.Replace function (for instance in .NET/C#)? I need that because, as many people, I would like to count the number of words in a field. However, I'm not satisfied with the following answer (given several times on that site): SELECT LENGTH(name) - LENGT...

regex: using surrounding brackets as delimiters while ignoring any inside brackets

Hello, I've build a complex (for me) regex to parse some file names, and it broadly works, except for a case where there are additional inside brackets. (?'field'F[0-9]{1,4})(?'term'\(.*?\))(?'operator'_(OR|NOT|AND)_)? In the following examples, I need to get the groups after the comment, but in the 3rd example, I am getting ((bracke...

Converting RE code from PHP to Python

I have done a simple program in PHP, now need to convert this into Python: $string="Google 1600 Amphitheatre Parkway Mountain View, CA 94043 phone"; preg_match_all('/[0-9]+.{10,25}[^0-9]*[0-9]{5,6}+\s/',$string,$matches); print_r($matches); ...

.NET Regex isMatch vs Matches question

Hi guys, yes it's another .net regex question :) (please excuse the long waffle leading up to the actual question) I'm allowing users to use simple date/time macros for entering dates quickly (they don't want a date picker) for example they can enter: d +1d -2h this will give them a date time string of todays's date, plus one day, min...

Mod Rewrite path issues

I have successfully created rewrite rules to handle URLs like http://example.com/xyz http://example.com/xyz/ http://example.com/xyz/abc http://example.com/xyz/abc/ Here is the mod rewrite & regex: Options +FollowSymlinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d Rewrite...

Remove all characters after "-"

I thought this would work but it appears to be only removing the - and the whitespace after it. $itemList[] = preg_replace('/-(.*?)/i', "", $temp['item']); ...

Error reading log file with reg expression

I am trying to read a log file with the content look like this: 127.0.0.1 - - [17/OCT/2009:00:02:14 0000] GET xxxxxx xxxx xxx I tried the following reg exp and I am getting ERROR: Unclosed group near index 90 regex = (\d+\.\d+\.\d+\.\d+)\s-\s-\s\[(\d+)/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\d{2})\s(\d{4}\)].* Can someone help me? ...

Regular Expression to find URLs in block of Text (Javascript)

I need a Javascript regular expression that scans a block of plain text and returns the text with the URLs as links. This is what i have: findLinks: function(s) { var hlink = /\s(ht|f)tp:\/\/([^ \,\;\:\!\)\(\"\'\\f\n\r\t\v])+/g; return (s.replace(hlink, function($0, $1, $2) { s = $0.substring(1, $0.le...

Regex behaving differently in IE6/IE7

My HTML is something like this : <select> <option>ABC (123)</option> <option>XYZ (789)</option> </select> What I'm trying to do is: using JQuery and a regex, I replace the "(" with <span>( here's my JQuery line: $(this).html($(this).html().replace(/\(/g,"<span>(")); It's working as intended in Firefox, chrome and safari, ...