regex

How does this regex find primes?

Possible Duplicate: How to determine if a number is a prime with regex? This page claims that this regular expression discovers non-prime numbers (and by counter-example: primes): /^1?$|^(11+?)\1+$/ How does this find primes? ...

Replacing html tag with preg_replace

I'm trying to match tags using preg_replace. The regex used is: <video[^>]*>(.*?)</video> But I'm getting a server warning: Message: preg_replace() [function.preg-replace]: Unknown modifier ']' Any clues on why? Also, How could I modify the regex so it can match [video] tags instead? Thanks! ...

PHP Regex Problem (username, birthdate, email address)

The below regex's don't seem to be working. Is it because of !preg_match? Username if (!preg_match("/^[A-Za-z](?=[A-Za-z0-9_.]{3,31}$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/",$_POST['username'])) { $hasErr = true; $return['username'] = 'Please enter a valid username. Use 4 to 32 characters ' . 'and start with a l...

How to use regex in java to change prefix and suffix of matching substrings

I'm wanting to (in Java) find any substrings in a string which start with say aba and end in say aca, where there is one or more non-whitespace chars between them. For example" blingblangabablahacablingblang would find the substring abablahaca. Then I want to replace each of those substrings, modifying the start to just b and the end t...

Validate twitter URL

Hi all, I am trying to validate a twitter url, so that at least it contains a username. I do not care if it exists or not, just that there is one. I am using the below javascript regex var re = new RegExp('((http://)|(www\.))twitter\.com/(\w+)'); alert(re.test('http://twitter.com/test_user')); but it is not working. The strange thi...

How to remove all html tags except img?

I got some html text, which contains all kinds of html tags, such as <table>, <a>, <img>, and so on. Now I want to use a regular expression to remove all the html tags, except <img ...> and </img>(and upper case <IMG></IMG>). How to do this? UPDATE: My task is very simple, it just print the text content(including images) of a html...

using RegEx to replace string

hi, i have this pattern i using to replace string: var html = "some test string"; var regex = new Regex(@"<(.|\n)+?>", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline); var result = regex.Replace(html, ?); this pattern matches all html tags <anything here> and replace with ?. actually ? is " " or "" accordin...

Regular Expressions to get text between tags

I am writing an application to get the title of an html page, some text under the body tag and an image. It is something like the share stuff of facebook. I can get a regular expression that does that. Thanks for your assitance. ...

How to get string from HTML with regex?

hello, I'm trying to parse block from html page so i try to preg_match this block with php if( preg_match('<\/div>(.*?)<div class="adsdiv">', $data, $t)) but doesn't work </div> blablabla blablabla blablabla <div class="adsdiv"> i want grep only blablabla blablabla words any help ...

how to do url rewriting in resin(railo)

Let's say users browse to http://www.site.com/test1/test2/test3 now I would like to rewrite the url to http://www.site.com/index.cfm?var1=test1&amp;var2=test2&amp;var3=test3 So far I have added the following in the resin.conf file: <web-app id="/" root-directory="webroot"> <rewrite-dispatch> <forward regexp="^/([^/]+...

How to match the last word in a sentence?

Suppose we have one sentence (several words without a dot after the last one). I need to wrap the last word with some html tags (for example, <strong>lastword</strong>). How can I achieve this with java regular expressions? I've already tried this: "John Doe Jr".replaceAll ("( .+$)", "<strong>$1</strong>"); but it results in John...

What are the meanings of these regular expressions in JavaScript?

1) ^[^\s].{1,20}$ 2) ^[-/@#&$*\w\s]+$ 3) ^([\w]{3})$ Are there any links for more information? ...

Regex.IsMatch, is applied on "byte level" or "string level"?

I would like to know if the result of RegEx.IsMatch is affected by encoding. I am checking if a string is contained within another one by using a regular expression pattern. I am 99.9 % sure the pattern is correct, so my question is... The matching test with the Regex.IsMatch, is applied on "byte level" or "string level"? UPDATE: ...

PHP find words which are not in regex

I have written following regular expression /^[A-Za-z0-9-_\s]*$/ in PHP which allows numbers, letters, spaces, hyphen and underscore. I want to display those matches which are not valid against the regex i.e "My Name is Blahblah!!!" should give me "!!!" output. ...

Common practice with validating emails?

I read an article the other day that briefly touched base on some common validation flaws in most modern websites, and I decided to do some research on it. Turns out, MOST websites, and email providers (hotmail, yahoo) are being TOO STRICT with their validation. - In section 2.3.10 of RFC 2821 Consequently, and due to a long hist...

How do I match a word that starts with "I" but isn't the word "Integer"?

How do I write a regular expression that will match all words starting with I except the word Integer? Example: t1: Integer; t2: Interface; t3: IXml; The result should be Interface and IXml. ...

How do I write a regular expression that will match if the 6th character of a string is one of two different letters?

I'm trying to write a validator for an ASP.NET txtbox. How can I validate so the regular expression will only match if the 6th character is a "C" or a "P"? ...

RegEx'ing Hotmail email addresses with C#

Unfortunately my hMailServer can't send emails to Hotmail. How can I determine whether a given email address is Hotmail or not, to prevent the message from being lost. Hotmail e-mails can be: * @live.com * @live.fr[pt][ru][etc] * @hotmail.com, * @live.com.jp * @msn.com * and many country TLD specific combinations involving MSN, Hotma...

Regular Expression Help - String - JWE-766.1.pdf - Pattern - Extract 766

Hi all, I would like some help with a regular expression. I have some files like this: JWE-766.1.pdf JWE-766.2.pdf JWE-768.1.pdf JWE-770.1.pdf I would like a regex pattern to extract the number after 'JWE-'. i.e. 766. Also, a regex expression to extract 1 and 2 from JWE-766.1.pdf and JWE-766.2.pdf respectively. Any help would be ...

Intelli-J structural search and replace problems...

Is there an easy way to capture types? I can't seem to do basic things like use variable expressions side by side, such as $mapType$$mapEnd$ to do a simple replacement. Is there any reason this might be? That is, if I have a single expression, say .*\s*.*abc, and I break it into two variables, .*\s* and .*abc, the expression does not mat...