regex

Regular Expression Help

Hi There, Does anyone have a regurlar expression available which only accepts dates in the format dd/mm/yy but also has strict checking to make sure that the date is valid, including leap year support? I am coding in vb.net and am struggling to work this one out. Many Thanks ...

Finding index inside a Javascript regular expression match.

i had string like this in javascript var str = "This is my test string is Ingrédients"; the substring "Ingrédients" can be also as "Ingredients" how to get the index of substring "Ingrédients" from the above string by applying regular expression ( Ingr[ée]dients ) ...

Regex for removing certain variable numeric values from some text

I want to substitute all 4 instances of the number 300 from the code below (which my website users will be pasting whenever they create a new blog post), with 470. <div> <object width="300" height="300"> <embed src="link-removed" width="300" height="300"></embed> </object> <p> <a href="another-link">link</a> </p> </div> ...

Regex to find external links from the html file using grep

hello, From past few days I'm trying to develop a regex that fetch all the external links from the web pages given to it using grep. Here is my grep command grep -h -o -e "\(\(mailto:\|\(\(ht\|f\)tp\(s\?\)\)\)\://\)\{1\}\(.*\?\)" "/mnt/websites_folder/folder_to_search" -r now the grep seem to return everything after the external li...

Regular expression ending with the first of two options

In Ruby, I'm trying to extract from text a string that starts with "who" and ends with the first of either a ")" or "when" (but doesn't include the ")" or the "when"). I've tried the following: who.*(?=when\b|\)) which fails the case where it finds both a "when" and a ")". Any ideas? Many thanks ...

A short "RewriteRule" regexp question

I have a very very long querystring which ALWAYS starts like this: mydomain.com/bincgi/sql_query.php?alot alot alot of variables passed along What is the regular expression to make a rewriteRule if I want to pass along all the variables but via this link: mydomain.com/search/all variables here instead..... So the last one is wh...

help with regex needed

I need a regular expression for which: the string is alphanumeric and have exactly 6 characters in the first half followed by hyphen(optional) followed by optional 4 characters:(cannot have more than 4 characters in the second half) so any of the following is valid 11111A 111111-1 111111-yy yyyyy-989 yyyyyy-9090 i thought this expr...

Regex, replace path to resource, modify resource name

Hi all, I'd like to use a JS regex to take a string such as the following: 'http://www.somedomain.com/some_directory/some_other_directory/some_image.jpg' And turn it into this: 'http://www.some_other_domain.com/another_directory/yet_another_directory/size1_some_image.jpg' Any hints? Additionally, any pointers for books or other re...

Finding all links and e-mail addresses in a string

What could be the easiest way to match all links and e-mail addresses in a string to a list array? I was using preg_match in PHP but in C# it looks like it will be way different. ...

Limit number of alpha characters in regular expression

I've been struggling to figure out how to best do this regular expression. Here are my requirements: Up to 8 characters Can only be alphanumeric Can only contain up to three alpha characters [a-z] (zero alpha characters are valid to) Any ideas would be appreciated. This is what I've got so far, but it only looks for contiguous lett...

regular expression for validation not working

I have a "description textarea" inside a form where user may enter a description for an item. This is validated with javascript before the form beeing submitted. One of the validation-steps is this: else if (!fld.value.match(desExp)){ And desExp: var desExp = /^\s*(\w[^\w]*){3}.*$/gm; Now my problem, this works fine on all cas...

Regex to match a Java method signature

I am having this particular requirement where a method has to be identified by different regular expressions for different components. For example, there need to be a regex for return parameter, one for method name, one for argument type and one for argument name. I was able to come up with an expression till this step as follows - ([^,...

Need help unformatting text

I am currently programming a Visual C# service to receive emails from various sources then I take certain info and organize it in a database using Regex to retrieve the deferent cell values (such as header, body, problem, cost, etc.etc.). My problem is that I am currently using a Hotmail account to email the service which the service th...

Javascript: using a wildcard character with a replace method

Hi all I have a String that contains a line of html code eg. '<b>1995</b>'. Let's say this String could also contain '<b>1997</b>' or '<b>1999</b>' etc. I want to use a replace method to remove the tags but leave the years. Is there a way to implement a wildcard character to do this, something like: first_string = "First year is <b>199...

Regular Expression - Password Validation is not working

Hi, I have to validate the password using regex. The password rule is like at least 1 uppercase and at least 2 numeric. It works fine except if the character comes at the end of the string. The regular expression which i am using is "^(?=.*\d.{2})(?=.*[A-Z].{1})(?=.*[@#$%^&+=].{2}).{8,12}$" Rules: minimum length = 8 minimum uppe...

How to check user input for correct formatting

This is what i've come up with so far private void CheckFormatting() { StringReader objReaderf = new StringReader(txtInput.Text); List<String> formatTextList = new List<String>(); do { formatTextList.Add(objReaderf.ReadLine()); } while (objReaderf.Peek() != -1); objReaderf.Close(); for ...

Compare http_referer value

My http_referer says this: http://www.domain.com/search/?etcetcetcetc... I need to compare my http_referer to look for this: http://www.domain.com/search And if the first part of the referer is this, then do some code... Ex: if($_SERVER['HTTP_REFERER']=='http://www.domain.com/search'){ do stuff... But first ...

[Single|Double|Or no] Quotes when using grep?

Grep acts differently depending on what kind of quotes I surround the regex with. I can't seem to get a clear understanding of why this is. Here is an example of the problem: hamiltont$ grep -e show\( test.txt variable.show(); variable.show(a); variable.show(abc, 132); variableshow(); hamiltont$ grep -e "show\(" test.txt gre...

R: Referencing a matched string in sub

How can I reference a matched string (or captured group) in R so as to append in a sub(). For instance, I would do it like this in sed to append a 'd' to the match echo "66xx" | sed 's/[0-9][0-9]/&d/g' 66dxx ...

Preg Replace Wordpress tags

Hello, I'm displaying wordpress content on my own site. However the content has such things as: [caption id="attachment_367" align="aligncenter" width="432" caption="Version 2010!!"] I would basically like to strip anything thats inside [] and the [] themselves. Help greatly appreciated! ...