regex

.NET Regex Expression For Finding & Replacing Any ProductName Value In A .vdproj File In C#

Greetings: I'm trying to write a NAnt extension task that can update different settings within a Visual Studio 2003 generated Setup .vdproj file, and would appreciate help with the following. Specifically, I would like to use a RegEx expression to find, and if found, replace any value string value assigned to the ProductName value with...

Regex for non-alphabets, non-numerals and non-DOT

Please provide a solution to write a regular expression as following in C#.NET: I would require a RegEx as below: Non-Alphabets(a to z;A to Z) and Non-Numerals(0 to 9) and also non-DOT (.). Mean to say as otherthan the mentioned above i want to handle reverse way for getting regular expression as other than alphabets, otherthan numerals...

Converting an eregi_replace to a preg_replace

I am trying to parse some HTML snippets and want to clean them up for various reasons (XSS et al). I am currently trying to remove all of the attributes on any tag, except for the href on a anchor. I am doing this using a sequence of eregi_replace calls, but I am sure there is a smarter way of doing this using preg_replace and just a c...

Regular expression to remove a file's extension

I am in need of a regular expression that can remove the extension of a filename, returning only the name of the file. Here are some examples of inputs and outputs: myfile.png -> myfile myfile.png.jpg -> myfile.png I can obviously do this manually (ie removing everything from the last dot) but I'm sure that there is a regular exp...

PHP & Regex : Adding website url to images

I have the following code below on my website. It's used to find the images in a block of html that don't have http:// or / in front. If this is the case, it will add the website url to the front of the image source. For example: <img src="http://domain.com/image.jpg"&gt; will stay the same <img src="/image.jpg"> will stay the same <im...

python 2.3 regex problem

how do i set the regular expressions flags like multiline and ignorecase in python 2.3? in python 2.6 its like this re.findall(pattern,string, re.multiline | re.ignorecase) but this doesn't seem to wok for python 2.3, any ideas? pointers appreciated edit: sorry, it was python 2.3 not 2.4 ...

Get url from html code using Regex

<div><a href="http://anirudhagupta.blogspot.com/"&gt;Anirudha Web blog</a></div> What is the Regular Expression to get http://anirudhagupta.blogspot.com/ from <div><a href="http://anirudhagupta.blogspot.com/"&gt;Anirudha Web blog</a></div> If you suggest in c# that's good i also like jQuery for do this. HTML code is also means for...

regexp should match site category URL, but matches /

the regexp \<div class=g\>.*?\<a href=\"?(http:\/\/stackoverflow.com\/)\"?.*?\>.*?\<a href=\"?(.+?)\"?.*?\>.*?\<\/div\> the target <div class=g> <link rel=prefetch href="http://stackoverflow.com/"&gt; <h2 class=r> <a href="http://stackoverflow.com/" class=l onmousedown="return rwt(this,'','','dres','1','AFQjCNERidL9Hb6OvGW93_Y...

regular expression using variables..

Hi..am just getting used to regex..but am unsure of how to use javascript variables within the regular expressions.. For example...as it stands..my code reads.. if (window.location.hostname == 'localhost') { var $sURLDomain = 'http://localhost/'; } else { var $sURLDomain = 'http://mysite.com'; } $('#content a[href^=$sURLDom...

C++ character replace

What is the best way to replace characters in a string? Specifically: "This,Is A|Test" ----> "This_Is_A_Test" I want to replace all commas, spaces, and "|" with underscores. (I have access to Boost.) ...

Regex for reformatting a string to a safe xml-tag

I'm currently trying to write a RegexReplace to ensure an input can be used as a valid XML-tag, meaning: no spaces, no special characters, only lowercase, etc... Is there a common approach to that or do I have to do it all from scratch? Example: string Invalid = "asd(%4 asKUd n!%mn &§a_As1"; // Invalid as a tag string Valid = Format...

parsing application/atom+xml in html page

we know that all blog show his blog 's rss feed by <link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog" /> but are you know any regex to get feedurl from this <link rel="alternate" type="application/rss+xml" title="MyBlog RSS Feed" href="http://feeds.feedburner.com/MyBlog...

Only execute script if entered email is from a specific domain

I am trying to create a script that will only execute its actions if the email address the user enters is from a specific domain. I created a regex that seems to work when testing it via regex utility, but when its used in my PHP script, it tells me that valid emails are invalid. In this case, I want any email that is from @secondgear...

How do I grab only one capture out of a Perl regular expression?

Is there an easier way to grab only one element out of a match other than doing the followng: my $date = ($xml_file =~ m/(\d+)-sys_char/)[0]; # or my $date = $1 if $xml_file =~ /(\d+)-sys_char/; Is there a flag to specify that m doesn't return an array but just one concatenated value of all the $# matches, so I can do:? my $date = ($...

Java regular expression to match _all_ whitespace characters

I'm looking for a regular expression in Java which matches all whitespace characters in a String. "\s" matches only some, it does not match &nbsp; and similar non-ascii whitespaces. I'm looking for a regular expression which matches all (common) white-space characters which can occur in a Java String. [Edit] To clarify: I do not mean ...

Regex, writing a toy compiler, parsing, comment remover

Hi, I'm currently working my way through this book: http://www1.idc.ac.il/tecs/ I'm currently on a section where the excersize is to create a compiler for a very simple java like language. The book always states what is required but not the how the how (which is a good thing). I should also mention that it talks about yacc and lex and s...

Finding a newline not immediately followed by a newline

(in PHP ... ) I'm trying to take a block of text and remove all hard line breaks so it can be re-wrapped to a specific line length using wordwrap(). However, since its possible to have multiple paragraphs, I'm assuming I need a way to remove a single newline, but not two in a row. If this is right, how can I say find \n but not \n\n in...

Javascript - replacing a word using regexp only if there's a space around it.

A cut down version of my code sort of looks like this: string="test test testtest testtest test"; replacer="test"; string=string.replace(new RegExp(' '+replacer+' ','gi')," REPLACED "); Now, I want to replace a word only if there's a space surrounding it, The code actually works fine but I'm just wondering why the one below which woul...

regex expression for escaped quoted string won't work in php's preg_match_all

I am trying to match quoted strings within a piece of text and allowing for escaped quotes within it as well. I tried this regular expression in an online tester, and it works perfectly. However, when I try it in preg_match_all, it fails at the first escaped string. Here is the code: $parStr = 'title="My Little Website" year="2007"...

asp.net regular expression validator client side script error

I have the following regular expression validator to detect whether an input string contains HTML/script tags and if so cause a vaidation error: <asp:TextBox ID="txt" runat="server" /> <asp:RegularExpressionValidator ControlToValidate="txt" runat="server" ID="regexVal" EnableClientScript="true" Dis...