regex

regex for changing height and width value in an embed code

HI I have an application where users can paste their embed code.While displaying I want to change the height and width of the embed code to a fixed value of my choice. Can you tell me the regular expression to find the width and height in the embed code. width="300" height="500". I want to be able to get these two values completely so t...

Allow only alphanumeric in textbox.

I have a textbox and it need the user not allow to enter any specialcharecters He can enter 1. A-Z 2. a-z 3. 0-9 4. Space. How can I make the KeyDown event to do this? ...

Regex for combining digits

I have a sequence of digits like below. I want to combine digits to group of 4. Can someone give a vim regex to do that? Input : 1234 56 7890 1234 The output should be: 1234 5678 9012 34 ...

Any good regular expression creator software or online tools to create Regular expressions..

Does anyone have any good link to a website or a good tool to create regular expressions rather than break your head to create one. The tool should be able to create regular expressions by simply selecting some sort of pattern text. For e.g If I want a phone number to be validated, I should be able to enter (000)-(111)-(1111) or 000-000-...

Cancelling a long running regex match?

Say I'm running a service where users can submit a regex to search through lots of data. If the user submits a regex that is very slow (ie. takes minutes for Matcher.find() to return), I want a way to cancel that match. The only way I can think of doing this is to have another thread monitor how long a match is taking and use Thread.stop...

Splitting a complex string with Regular Expressions

How do I, using a regular expression, split this string: string = "a[a=d b&c[e[100&2=34]]] e[cheese=blue and white] x[a=a b]" into this array: string.split( regexp ) => [ "a[a=d b&c[e[100&2=34]]]", "e[cheese=blue and white]", "x[a=a b]" ] The basic rule is that string should be split at whitespace ( \s ), unless whitespace exists ...

extract urls from text in PHP

Hello I have this text $string = "this is my friend's website http://example.com I think it is coll"; how can I extract the link into another variable I know it should be by using regular expression especially "preg_match" but I don't know how? Thanks ...

Regex pattern to match Switch Case statements.

Hi, We need to identify and then process switch/case statements in code based on some business rules. A typical switch statement: switch (a) { case "A": case "B": result = "T"; result1 = "F"; default: result = "F"; ...

Regex to replace string with another string in MS Word?

Can anyone help me with a regex to turn: filename_author to author_filename I am using MS Word 2003 and am trying to do this with Word's Find-and-Replace. I've tried the use wildcards feature but haven't had any luck. Am I only going to be able to do it programmatically? ...

How to stop regex matching after 1 match without using non-greedy character

Is there anyway to get a regex pattern to automatically stop searching after one match. I'd like to add regex searching to a web service I'm trying to create, but I don't want someone to be able to run a regex that would take a long time, just one match is good enough. Is this possible? ...

Regex in MS Word to acquire word previous to the found one?

Basically I am using MS Word's find and replace feature (wildcard:true) but the text I have to edit contains stuff that messes up the search: //more text in different format above <file name="london_bitmap" bits="24", owner="sergio"> 1 2 3 </file> <file name="paris_bitmap" bits="24", owner="sergio"> 1 2 3 </file> <file name="moscow_bi...

Replace each RegExp match with different text in ActionScript 3

Hi, I'd like to know how to replace each match with a different text? Let's say the source text is: var strSource:String = "find it and replace what you find."; ..and we have a regex such as: var re:RegExp = /\bfind\b/g; Now, I need to replace each match with different text (for example): var replacement:String = "replacement_" +...

Regular expressions

I am trying to write a regular expression that will get the last ':' and everything after it. This is my regular expression in C#: Regex rx5 = new Regex(@"[A-Za-z.][^\s][^:]{1,}$",RegexOptions.Singleline); it works except it includes the ':' in there. How do I just get everything after the ':' not including the ':'? ...

How can I select the tag-name and attributes AND values of those attributes with ONE regular expression?

Hi, I have the following Regular Expression from this post (Regular expression for extracting tag attributes). (\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>"\']))+.)["\']? I've created the following PHP code and it works nicely. I get [id='gridview1' and 'id' and 'gridview1'] from the preg_match_all() function. $regexp = '/(\S+)=["\']?...

How to rewrite ALL urls while skipping certain folders?

Hi, i'm trying to rewrite my urls to goto a single php file: RewriteRule ^dir/(?:(?!style|js).)*$ http://www.domain.com/single.php?uri=$1 [QSA] However the exclusion of /dir/js and /dir/style isn't working as i was hoping it would... [redirects] domain.com/dir [redirects] domain.com/dir/jason [redirects] domain.com/dir/jason/pete [...

Javascript match and replace with unicode

I have some javascript which reads some cookies, and does some matching. I am using groupings to catch parts of a regular expression and use them later. I am having an issue with unicode characters though. If I have a character like \u25BA ►, when I find this character in a grouping, it returns the string '\u25BA' instead of the unicode ...

How can I find out how many capturing brackets are in a Perl regexp?

If I am given a rexexp in Perl, can I find out how many capturing brackets there are? So, for example: \w -> 0 (\w) -> 1 (\w(\w)) -> 2 ...

Checking visitors IP against a table of IPs. Some wildcards.

I have a script that loops through an array of IP's and checks the clients IP against them. //filter IP address list $ip = array(); $ip[] = '10.10.5.*'; $ip[] = '234.119.260.65'; $ip[] = '234.119.254.2'; function testIP($ip){ //testing that correct IP address used for($i=0, $cnt=count($ip); $i<$cnt; $i++) { $ipregex = preg_replace...

Regular Expression for Stripping Strings from Source Code

Hello, I'm looking for a regular expression that will replace strings in an input source code with some constant string value such as "string", and that will also take into account escaping the string-start character that is denoted by a double string-start character (e.g. "he said ""hello"""). To clarify, I will provide some examples...

What is the REGEX to match this pattern in a html document in C#?

I really can't work out how to best do this, I can do fairly simple regex expressions, but the more complex ones really stump me. The following appears in specific HTML documents: <span id="label"> <span> <a href="http://variableLink"&gt;Joe Bloggs</a> now using </span> <span> ' <a href="/variableLink/">Important Data</a> ' </span> <sp...