regex

Regular expression throwing exception.. Help needed

I am using a regular expression which gets the substring associated with a match i.e "(MAC:[A-Z0-9]{12})" This regex will find the occurences of MAC:(Some characters) in a string. This regex is working for characters less than 10 i.e "(MAC:[A-Z0-9]{8})" - WORKS but, "(MAC:[A-Z0-9]{8})" - THROWS EXCEPTION Any help appre...

What regex can I use to find two dashes? ie. --

Hi folks, pretty simple -> a regex query to find two dashes in a string. If a string has more than two dashes, then it returns the index of the first two dashes. eg. PASS: fdhfdjkgsdf--sdfdsfsdsf PASS: sldfjkdsf------dsfdsf----fds FAIL: asdasdsa FAIL: asd-dsadsaads ...

JavaScript regex replace - but only part of matched string?

I have the following replace function myString.replace(/\s\w(?=\s)/,"$1\xA0"); The aim is to take single-letter words (e.g. prepositions) and add a non-breaking space after them, instead of standard space. However the above $1 variable doesn't work for me. It inserts text "$1 " instead of a part of original matched string + nbsp. Wh...

How to escape slashes in single-quote-like string?

ruby 1.8.6 (2007-09-24 patchlevel 111) str = '\&123' puts "abc".gsub("b", str) => ab123c puts "abc".gsub("b", "#{str}") => ab123c puts "abc".gsub("b", str.to_s) => ab123c puts "abc".gsub("b", '\&123') => ab123c puts "abc".gsub("b", "\&123") => a&123c <--- This I want to achieve using temporary variable If I change str = '\&123' to str...

Regular Expression

Hello I need to extract the string MAC:BFEBFBFF000006FB00:1E:37:54:AE:C8 out of "ADMIN:1EXT:0NOR:0OUT:1PRI:1BAT:1MOD:1MAC:BFEBFBFF000006FB00:1E:37:54:AE:C8" The regular expression i use is "(MAC:[A-Z0-9]{10})+" But still i do not get the intended result Please help !! ...

Return positions of a regex match() in Javascript?

Is there a way to retrieve the (starting) character positions inside a string of the results of a regex match() in Javascript? ...

Regex for Time Format

Regex needed for a time of the format: 12-02-30T00:59:43. Also, I've not managed to find any decent websites or books that contain good explanations or reference material for regular expressions. Can anyone recommend any? ...

Count html links in a string and add a list

Hi. I store the content of a website in a string $html. I want to count all html links that link to a file in the .otf format, add a list of these links to the end of $html and remove the original links. An example: <?php $html_input = ' <p> Lorem <a href="font-1.otf">ipsum</a> dolor sit amet, consectetur <a href="http://ww...

Finding C#-style unescaped strings using regular expressions

I'm trying to write a regular expression that finds C#-style unescaped strings, such as string x = @"hello world"; The problem I'm having is how to write a rule that handles double quotes within the string correctly, like in this example string x = @"before quote ""junk"" after quote"; This should be an easy one, right? ...

Retrieve XML Namespaces using Regex

Given an XML fragment that I want to parse with XPath I first need to extract the namespaces to add to the namespace manager. I've been trying to figure out the Regex pattern needed to extract xml attributes that define a namepspace. For example I want to get all the namespaces which I can do some more basic string manipulation on to sep...

Python Regex Help (httplib2 cookies)

Having the same problem as the poster of this question: http://stackoverflow.com/questions/1738227/httplib2-how-to-set-more-than-one-cookie The cookie looks like this.. PHPSESSID=8527b5532b6018aec4159d81f69765bd; path=/; expires=Fri, 19-Feb-2010 13:52:51 GMT, id=1578; expires=Mon, 22-Feb-2010 13:37:51 GMT, password=123456; expires=M...

The regex test in jQuery's parseJSON returns false - why?

I don't understand why the test in jQuery's parseJSON function: /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") .replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]") .replace(/(?:^|:|,)(?:\s*\[)+/g, "")) returns false for the string: {"TermTitle":"some...

Splitting a string at every n-th character

In JavaScript this is how we can split a string at every 3-rd character "foobarspam".match(/.{1,3}/g) I am trying to figure out how to do this in Java. Any pointers? ...

Ruby URL regex matcher

Hey, I have some content with a list of URLs contained in it. I am trying to grab all the URLs out and put them in an array. I have this code content = "Here is the list of URLs: http://www.google.com http://www.google.com/index.html" urls = content.scan(/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*...

Free Windows GUI text editor supporting Regular Expressions, for programmers?

Looking for a free Windows GUI text editor that supports solid1 regular expressions for its Find/Replace features, for programmers to use. Familiar with Vim, Ed, Emcas, etc. Not looking for a command-based editor. Will give chosen editor to team members already familiar with Regular Expressions, but don't want learning curve incurred to...

Why are there so many different regular expression dialects?

I'm wondering why there have to be so many regular expression dialects. Why does it seem like so many languages, rather then reusing a tried and true dialect, seem bent on writing their own. Like these. I mean, I understand that some of these do have very different backends. But shouldn't that be abstracted from the programmer? I'm ...

PHP Regex Replace with Backreference modified by functions

I want to replace the class with the div text like this : This: <div class="grid-flags" >FOO</div> Becomes: <div class="iconFoo" ></div> So the class is changed to "icon". ucfirst(strtolower(FOO)) and the text is removed Test HTML <div class="grid-flags" >FOO</div> Pattern '/class=\"grid-flags\" \>(FOO|BAR|BAZ)/e' Replacement ...

Regex for extenionless URL

In my asp.net application i have url www.site.com/rugby to match it i have regex "~/(.+)" which works perfectly fine. But if i navigate to www.site.com/login.aspx again regex matches with this expression "/(.+)". In Simple words i want a regex which only match the extenionless url. IF extension is present in the url then do not match ...

How to copy marked text in notepad++

I have a part of HTML source file that contains strings that I want to select and copy at once, using the regex functionality of Notepad++. Here is a part of the text source: <option value="Performance" >Performance</option> <option value="Maintenance" >Maintenance</option> <option value="System Stability" >System Stability</option> ...

Parts of a match in regular expression with egrep

Hello! I was wondering if, with egrep ((GNU grep) 2.5.1), I can select a part of the matched text, something like: grep '^([a-zA-Z.-]+)[0-9]+' ./file.txt So I get only the part which matched, between the brackets, something like house.com Instead of the whole line like I usually get: house.com112 Assuming I have a line with h...