regex

Replacing a Regex Match Collection in C#

I need to find in a text everything that starts with [ and ends with ] and replace it with the value that a function returns. So, here is an example of what I'm doing: public string ProcessTemplate(string input) { return Regex.Replace(input, @"\[(.*?)\]", new MatchEvaluator(delegate(Match match) { ...

Replacing a string inside a string in PHP

I have strings in my application that users can send via a form, and they can optionally replace words in that string with replacements that they also specify. For example if one of my users entered this string: I am a user string and I need to be parsed. And chose to replace and with foo the resulting string should be: I am a user s...

Zend Route Regex: Match controller segment of Url to anything but "home"

I am working with Urls in the following format: "controller/action" where the slash is required. I need to create a PCRE regex to match the controller and action names unless the controller name has the value of "home." For example: "member/update" should produce "member", "update" "admin/index" should produce "admin", "index" "home/i...

Convert spaces to tabs in RegEx

How do do you say the following in regex: foreach line look at the beginning of the string and convert every group of 3 spaces to a tab Stop once a character other than a space is found This is what i have so far: /^ +/\t/g However, this converts every space to 1 tab Any help would be appreciated. ...

What regular expression matches this pattern: 22-NOV-09

I have tried: /^([0-3][0-9])-(A-Za-z)-([0-1][0-9])?$/ and am not having success. What am I doing wrong? Thank you folks! ...

using Regex to find and replace doubles (C#)

I want to replace all double tokens in string with the double value appended with "c" letter. Is there an easy way to do it? I thought that the Regular Expression is the way to go for example, I wanna change the following treand60(12.3)/1010 + 1 >1010 with treand60(12.3c)/1010c + 1c >123c any suggestions ...

PHP Markdown \n Question

I'm using http://michelf.com/projects/php-markdown/ for my markdown library and my question is that if i edit and remove the \n\n functionality would this work Because the users that i have, are quite probably not allowed to run JavaScript therefore i cant count on the preview to be generated dynamically therefore they will make allot o...

regex to match p tags and add br's inside of them

Well the question title explains the question :D but here is an example none the less asdf asdf <p>asdf asdf asdf</p> how to i get it to regex the inside of the p tags and apply nl2br to it so the output would be: asdf asdf <p>asdf<br /> asdf<br /> asdf</p> Edit: In PHP ...

Javascript - Removing part of url with regex

Hello, I may have URLs like: http://193.198.112.125/foo/bar/ http://www.site.com/foo/bar/ http://193.198.112.125:4000/foo/bar/ and what I would like to do is to remove part before /foo/bar/, with regex which will work if I have IP/something, IP:PORT/something or DOMAIN/something Tnx! ...

Regexp that matches all the text content of a HTML input

I have articles on my website which I would like to get corrected and translated automatically. But I need to get the content, without having the HTML tags around. The idea is to have a regex that could retrieve all the content between the tags (and, if possible, also the content found in tags fields like <img alt='Little house'>). The ...

Find href attribute values that do not contain “javascript:”

I have a RegEx which nicely finds the href's in a URL: <[aA][^>]*? href=[\"'](?<url>[^\"]+?)[\"'][^>]*?> However, I want it to NOT find any href that contains the text, 'javascript:' in it. The reason is that I sometimes need to mod the href and sometimes don't. When there is a 'javascript:' text in the href I want it not to be found...

RegEx ignore in java

Hi i've got a String like "DE32424;WV424324;FR234324;DE45345" How would I ignore everything after the first ; so only DE32424 would be left in the string after using .replaceAll() in JAVA. ...

Perl Regexes - Replacing certain instances of matches

I'm trying to replace text in a source file much like how the C preprocessor works. My approach is to parse constants and their values and populate a hash array with them. My problem is as follows: In the source file, I have: #define CONSTANT 10 #define CONSTANT_PLUS_ONE CONSTANT + 1 I use /^#define\s+(\w.*)\s+.*($key).*/ to match...

Dealing with Negative Numbers in Strings

I have a simple, but perplexing problem, with Math. The following code will take a number from a string (usually contained in a span or div) and subtract the value of 1 from it. .replace(/(\d+)/g, function(a,n){ return (+n-1); }); This works really well, except when we get below zero. Once we get to -1 we're obviously dealing with neg...

Regular expression to verify that string contains { }

Hi guys I need to write a regular expression to verify that a string contains { } but not { or }.Can someone shine some light on this please? Thanks for all the help , here are some examples. e.g. valid : {abc}, as09{02}dd, {sdjafkl}sdjk, sfdsjakl,00{00}00, aaaaa{d} invalid: {sdsf , sdfadf},sdf{Sdfs ,333}333 ****Update**************...

PHP regex expression for the following...

<p>This will serve as a debug page.</p> <p><img src="http://mattmueller.me/blog/wp-content/uploads/2009/12/threadless.png" alt="Threadless" title="Threadless" width="650" height="150" class="alignnone size-full wp-image-73" /></p> <p>This will serve as a debug page.</p> <img src="http://mattmueller.me/blog/wp-content/uploads/2009/12/thr...

Simple question, comma delimited id's to array in php 5.2

I've got a comma delimited string of id's coming in and I need some quick way to split them into an array. I know that I could hardcode it, but that's just gross and pointless. I know nothing about regex at all and I can't find a SIMPLE example anywhere on the internet, only huge tutorials trying to teach me how to master regular expres...

what does this backtick ruby code mean?

while line = gets next if line =~ /^\s*#/ # skip comments break if line =~ /^END/ # stop at end #substitute stuff in backticks and try again redo if line.gsub!(/`(.*?)`/) { eval($1) } end What I don't understand is this line: line.gsub!(/`(.*?)`/) { eval($1) } What does the gsub! exactly do? the meaning of regex ...

Java Inner Text (getTextContents()) Problem

I'm trying to do some parsing in Java and I'm using Cobra HTML Parser to get the HTML into a DOM then I'm using XPath to get the nodes I want. When I get down to the desired level I call node.getTextContents(), but this gives me a string like "\n\n\nValue\n-\nValue\n\n\n" Is there a built in way to get rid of the line breaks? I would ...

making graphs with a shell script

i need to make a graph with numeric values in a time period, the values represent online users in a web page. the script will be exectued with cron every 30 mins and the needed html file will be downloaded with wget. but there are some yet unanswered questions & problems: -i need to get just the numeric value from html code (but grep r...