regex

How can I replace every instance of a pattern in ruby?

string.sub looks like it only replaces the first instance. Is there an option for that or another method that can replace all patterns? Can you do it inside a regex like perl? (I think something like r/blah/blah/) ... and +1 to anyone who can tell me WHY ON EARTH does string.sub replace just the FIRST match? ...

What's a good online regex editor?

I'm looking for something that supports ajax so it's more responsive. It should support the same regex flavor that PHP does. Normally I use Rubular, which is a good example of what I'm asking for, but the problem is that it's based on Ruby's regex engine, which does not support lookaheads or lookbehinds (which are supported in PHP). ...

Reg Exp To Remove 'onclick' from HTML elements (Notepad++)

Hi, I have a big html file (87000+ lines) and want to delete all occurrences of onclick from all elements. Two examples of what I want to catch are: 1. onclick="fnSelectNode('name2',2, true);" 2. onclick="fnExpandNode('img3','node3','/include/format_DB.asp?Index2=3');" The problem is that both function names and parameters passed to...

Regex to strip out links using Yahoo Pipes

Hi, everyone. i am working on school project and i have been struggling to clean all links in a feed using yahoo pipes. For instance removing <a href="http://mickey.com"&gt;Go to Source</a> from my item.description. Leaving the" Go to source" without the active link I am using the regex module and i tried to use this expression #</?...

RegEx, preg_replace_callback Question PHP

This is what I've got for for my RegEx, I was wondering if this is the best way. I want to be able to find something similar regardless of the spacing between Identifiers and not be case sensitive. And if possible, not worry about order.. Example: [Foreclosure ="Remax" URL="http://www.remax.com" Title = "4 Bedroom 2 Bath Condo"] [F...

Split string twice and adding to dictionary

Hey, I have this code: foreach (string x in Value.Split('|')) { var y = x.Split(','); if (y.Length == 1) Options.Add(y[0], y[0]); else if (y.Length == 2) Options.Add(y[0], y[1]); } It should process strings like: b|123|1,op|999 1|2|3|4 ... and add them to a Dictionary<string, string>. It splits the str...

PHP - help with my REGEX-based recursive function.

I'm extracting a string from wikipedia API that initially looks like this: link text. I want to peel off all {{...}} and everything in between them (could be any kind of text). For that I thought about using a recursive function with "preg_match","preg_replace". something like: function drop_brax($text) { if(preg_match('/{{(.)*}}/',...

Quick regexp needed for parsing a string

I have a few strings in the following format: S25 22.087 E152 46.125 S23 32.230 E148 10.576 S25 00.039 E152 12.480 S26 19.496 E152 43.501 I would like to parse the strings and split them into two parts, so: $foo = 'S25 22.087 E152 46.125'; would become: $foo[0] = 'S25 22.087'; $foo[1] = 'E152 46.125'; (it doesn't have to be in an ...

Remove Duplicate Line in Vim?

I'm trying to use VIM to remove a duplicate line in an XML file I created. (I can't recreate the file because the ID numbers will change.) The file looks something like this: <tag k="natural" v="water"/> <tag k="nhd:fcode" v="39004"/> <tag k="natural" v="water"/> I'm trying to remove one of the duplicate k="natural" v="wat...

Creating Regular Expressions in Python

Hi All, I'm trying to create regular expression that filters from the following partial text: amd64 build of software 1:0.98.10-0.2svn20090909 in archive what I want to extract is: software 1:0.98.10-0.2svn20090909 How can I do this?? I've been trying and this is what I have so far: p = re.compile('([a-zA-Z0-9\-\+\.]+)\ ([0-9\:\...

C++ Boost: Split String

How can I split a string with Boost with a regex AND have the delimiter included in the result list? for example, if I have the string "1d2" and my regex is "[a-z]" I want the results in a vector with (1, d, 2) I have: std::string expression = "1d2"; boost::regex re("[a-z]"); boost::sregex_token_iterator i (expression.begin (), ...

Is there a truly universal wildcard in Grep?

Really basic question here. So I'm told that a dot . matches any character EXCEPT a line break. I'm looking for something that matches any character, including line breaks. All I want to do is to capture all the text in a website page between two specific strings, stripping the header and the footer. Something like HEADER TEXT(.+)FOOTER...

Is this the RegEx for matching any cell reference in an Excel formula?

I have been trying to create a regular expressions pattern that matches any reference in any Excel formula, including absolute, relative, and external references. I need to return the entire reference, including the worksheet and workbook name. I haven't been able to find exhaustive documentation about Excel A1-notation, but with a lot...

How To Do PHP IF And Else With Regex

Hey Guys I Am Trying To Use One Regex Pattern If And Else //$pattern = "%http://depositfiles.com/[a-z]{2}/files/[0-9-a-z-A-z]*%"; //$pattern = "%http://depositfiles.com/files/[0-9-a-z-A-z]{9}%"; i just want to use one regex pattern to match the depositfiles $subject = 'http://depositfiles.com/files/9178jwt09 http://depositfil...

Return a regex match in a BASH script, instead of replacing it

I just want to match some text in a BASH script, i’v tried using sed, but I can’t seem to make it just output the match instead of replacing it with something. echo -E "TestT100String" | sed 's/[0-9]+/dontReplace/g' Which will output: TestTdontReplaceString Which isn’t what I want, I want it to output: 100 Ideally I would want it to...

PHP - recursive regular expressions

In a project I have a text with patterns like that: {| text {| text |} text |} more text I want to get the first part with brackets. For this I use preg_match recursively. The following code works fine already: preg_match('/\{((?>[^\{\}]+)|(?R))*\}/x',$text,$matches); But if I add the symbol "|", I got an empty result and I don't kn...

PHP preg_replace non-greedy trouble

I've been using the following site to test a PHP regex so I don't have to constantly upload: http://www.spaweditor.com/scripts/regex/index.php I'm using the following regex: /(.*?)\.{3}/ on the following string (replacing with nothing): Non-important data...important data...more important data and preg_replace is returning: more ...

How to remove both html tags & content,values inside the tags using regular expressions

How to remove both html tags & content,values inside the tags using regular expressions ...

Most efficient method to parse small, specific arguments

I have a command line application that needs to support arguments of the following brand: all: return everything search: return the first match to search all*search: return everything matching search X*search: return the first X matches to search search#Y: return the Yth match to search Where search can be either a single keywor...

python url fetch help - regex

I have a web site where there are links like <a href="http://www.example.com?read.php=123"&gt; Can anybody show me how to get all the numbers (123, in this case) in such links using python? I don't know how to construct a regex. Thanks in advance. ...