regex

Link wrappers for internationalization purposes

Hi, I am currently internationalizing my site using PHP and ran into this problem. Some string have multiple links in them so I would like to put the links in wrappers to make it easier for translators to translate (since I'm using gettext). For example: The <a href="google.com">dog</a>, <a href="bing.com">cat</a>, and <a href="yahoo....

Javascript replace doesn't work when it should.

var src = "http://blah.com/SOMETHING.jpg"; src.replace(/.*([A-Z])\.jpg$/g, "X"); at this point, shouldn't src be: http://blah.com/SOMETHINX.jpg If I use match() with the same regular expression, it says it matched. Regex Coach also shows a match on the character "G". ...

Regex to remove onclick="" attributes from HTML elements in ASP.NET C# (Server-side)

I'm trying to write a regex function to remove onclick (also onload, onmouseover etc.) attributes from HTML elements. I want to do this on the server side before the HTML is sent to the client. I have content coming from a Rich Text editor and being displayed on screen in a div, and I want to protect against XSS (Cross Site Scripting). ...

Regex to split a string only by the last whitespace character

Hello, hopefully this should be a quick and simple one, using PHP I'm trying to split a string into an array but by only the last instance of whitespace. So far I have... $str="hello this is a space"; $arr=preg_split("/\s+/",$str); print_r($arr); Array ( [0] => hello [1] => this [2] => is [3] => a [4] => space ) ...which split...

Is there a PHP function that can escape regex patterns before they are applied?

Is there a PHP function that can escape regex patterns before they are applied? I am looking along the lines of the C# Regex.Escape function. ...

Deleting (near) Duplicate Files

What's the best scripted way to delete (near) duplicate files based on filespec in Windows (XP in this case)? I am thinking of RegEX and some VB Script but if there is a better way... Examples include filenames that slighlty differ in name either with one or two (known) extra characters at the end or beggining but are identical in size,...

Finding repetition by Vim's Regex and globbing

How can you find the repetiting sequences of at least 30 numbers? Sample of the data 2.3758542141230068337129840546697038724373576309794988610478359908883826879271070615034168564920273348519362186788154897494305239179954441913439635535307517084282460136674259681093394077448747152619589977220956719817767653758542141230068337129840546697...

How to get date from this string - regex?

Hi, I have this string: \tid [email protected]; Tue, 6 Oct 2009 15:38:16 +0100 and I want to extract the date (emboldened) to a more usable format, e.g. 06-10-2009 15:38:16 What would be the best way to go about this? thanks in advance leddy ...

grep - search for "<?\n" at start of a file

I have a hunch that I should probably be using ack or egrep instead, but what should I use to basically look for <? at the start of a file? I'm trying to find all files that contain the php short open tag since I migrated a bunch of legacy scripts to a relatively new server with the latest php 5. I know the regex would probably be '/...

How do I remove the non-numeric character from a string in java?

I have a long string. What is the regular expression to split the numbers into the array? ...

Efficient Django QuerySet regex

I have a model like this: class CampaignPermittedURL(models.Model): hostname = models.CharField(max_length=255) path = models.CharField(max_length=255,blank=True) On a frequent basis, I will be handed a URL, which I can urlsplit into a hostname and a path. What I'd like is for the end user to be able to enter a hostname (yaho...

Regex/lastIndex - Unexpected behaviour

I know there are a few regex/lastIndex discrepancies but this one is new to me! Expected behaviour: Creating a new regular expression (with literal/constructor) will, obviously, create a new RegExp object with a lastIndex property set to zero. Actual behaviour: (in FF, Chrome): The lastIndex property seems to persist through multiple R...

Generate all Permutations of text from a regex pattern in C#

So i have a regex pattern, and I want to generate all the text permutations that would be allowed from that pattern. Example: var pattern = "^My (?:biological|real)? Name is Steve$"; var permutations = getStringPermutations(pattern); This would return the list of strings below: My Name is Steve My real Name is Steve My biological ...

Help with simple regular expression

I going to admit that I am hopeless at writing regular expressions. So can anyone please offer assistance in writing an expression (in C#) that will match the following cases: value(Plugin.Tests.Business.Services.Repositories.Maps.SomeTests+<>c__DisplayClass2). value(Plugin.Tests.Business.Interfaces.SomeOtherClass+<>c__DisplayClass3). ...

Regular expression help

I want to scrape data from HTML. The data I want is "Health Niche blogs". What regex to write? fo width="80%" noWrap>Author: Health Niche Blogs | Published: Se ...

Simple Regex Programming Problem

I am using Yahoo Pipes to take a twitter feed and filter information out. Pipes' regex function is a replace ______ with ____ iteration. My example is: Testbedots: happy "twins" I am trying to find a regex string that will select everything but what is within the double quotations. I am assuming there will only be one set of quot...

Regex look-behind without obvious maximum length in Java

I always thought that a look-behind assertion in Java's regex-API (and many other languages for that matter) must have an obvious length. So, STAR and PLUS quantifiers are not allowed inside look-behinds. The excellent online resource regular-expressions.info seems to confirm (some of) my assumptions: "[...] Java takes things a step...

RegExp alternative to negative lookahead match for Google Analytics

I'm setting up some conversion funnels on Google Analytics. One is to analyse traffic going from the main site to a secondary promotional site running on a virtual directory (on the same domain though) I should add, this is a setup form in Google Analytics, I can't using another other code (PHP, JS, C# etc) and it has to be done in one ...

javascript - search multiple html #ID and pass to function

Hiya, I've got an order form, to which I can append fields by clicking a button. I've got some back end javascript running which totals up the order price, but the grand total script is eluding me. My problem is that I need the script to seach the entire DOM and find how many have an ID which matches the following pattern. totprice0...

Regex to match content between given characters

What is need is given the following string "Other Text [[MyText]] Some Other Text", and given some specific characters like "[[" for start and "]]" for end, to be able to match "[[MyText]]". Given the following regex = "(\[\[)(.*)(\]\])" I am able to match what I want, but not exactly. Lets say I have this string "Other Text[[ Somethin...