regex

JavaScript replace with callback - performance question

In JavaScript, you can define a callback handler in regex string replace operations: str.replace(/str[123]|etc/, replaceCallback); Imagine you have a lookup object of strings and replacements. var lookup = {"str1": "repl1", "str2": "repl2", "str3": "repl3", "etc": "etc" }; and this callback function: var replaceCallback = functio...

Can I store and call regex in variables for later use?

I plan on storing regular expression codes in a database, but not sure how to get them from a variable to function. Any advise? $i = "([wx])([yz])" $j = "[^A-Za-z0-9]" $k= "([A-Z]{3}|[0-9]{4})" //Wold this execute properly, this really is the extent of my question? preg_match($i, $string); ...

jQuery element with multiple classes: storing one class as a var

I'm trying to create a standardized show/hide element system, like so: <div class="opener popup_1">Click Me</div> <div class="popup popup_1">I'm usually hidden</div> Clicking on the div with the opener class should show() the div with the popup class. I don't know how many opener/popup combinations I'm going to have on any given page,...

PHP RegEx: How to Stripe Whitespace Between Two Strings

I have been trying to write a regex that will remove whitespace following a semicolon (';') when it is between both an open and close curly brace ('{','}'). I've gotten somewhere but haven't been able to pull it off. Here what I've got: <?php $output = '@import url("/home/style/nav.css"); body{color:#777; background:#222 url("/home/st...

RegEx - Remove HTML hyperlinks based on the link text

Hi, I have some text that has HTML hyper-links in it. I want to remove the hyperlinks, but only specific ones. e.g. I start with this: This is text <a href="link/to/somewhere">Link to Remove</a> and more text with another link <a href="/link/to/somewhere/else">Keep this link</a> I want to have: This is text and more text with anothe...

How can I display a list of characters that fail to match a regular expression?

For example, if I'm doing some form input validation and I'm using the following code for the name field. preg_match("/^[a-zA-Z .-]$/", $firstname); If someone types in Mr. (Awkward) Double-Barrelled I want to be able to display a message saying Invalid character(s): (, ) ...

How can I write a regular expression that will not match if a string contains a particular substring?

Example: Suppose in the following example I want to match strings that do not contain the word "NOOOT". Example A: This shirt is NOOOT black. Example B: This shirt is black. I want something a little bit like the like the non-matching character class (e.g. [^abc]), but for whole strings: .*?(^NOOOT).*? Does such a creature exist? ...

(php) regexto remove comments but ignore occurances within strings

Hi there, I am writing a comment-stripper and trying to accommodate for all needs here. I have the below stack of code which removes pretty much all comments, but it actually goes too far. A lot of time was spent trying and testing and researching the regex patterns to match, but I don't claim that they are the best at each. My problem...

Replace a div content with PHP

hi everybody, yesterday, I posted a question about "Hom to change a DIV id with a php function" and someone found the right answer with a regular expression. The problem is that I wanted to use this answer to aplly the method on other same problems. But, as I'm very bad at regular expressions, I couldn't. So the problem is that I upl...

Regex only retrieves the first necessary element but not all of them

Can anybody help me with retrieving some elements from the following example text: sdfaasdflj asdfjl;a AB-12/34 BC-/85 CD-//8 DD-77 DE-78/9 EE-78-98 asdf; asdjf It is necessary to get the following elements: AB-12/34, BC-/85, CD-//8, DD-77, DE-78/9 When I'm using a regular expression like this: \s*(?<elements>\b[A-Z]{2}-[/0-9]+\b) ...

Regular expression for a facebook proxy email address.

What would be the regular expression to match a facebook proxy email address of a facebook user? ...

Regular expression for a list of numbers without other characters

I need a regular expression for a list of numbers in a text box with carriage returns and line feeds, but no other characters. e.g. 1234 5678 5874 3478 I have this: Regex(@"\d\r\n${0,}?"); ... but it is accepting commas when I paste them into my text box: e.g. 1234, 5678 5874, 3478 Can someone please tell me what I'm doing...

In C# VS2008 how to replace new SqlParameter("@values", SqlDbType.SomeType, 1500)) to ("@values", SqlDbType.SomeType, 1500

I have a lot of C# VS2008 code that looks like this: new SqlParameter("@Description", SqlDbType.NChar, 1500) or this: new SqlParameter("@IsRequired", SqlDbType.Bit) I want to change this code throughout my project there are thousands of occurrences of this pattern. How can I write a regular expression to remove the new SqlParam...

How to use ^/$ if it's already used as a delimiter for regex in PHP?

$regex = '$....$' $regex = '^...^' In the above two cases,how to use ^/$ to match the beginning/end of a string? ...

URL Friendly regular expression

Can anyone help me with regular expression for this: basically I have a search form and users type in whatever keywords they want to search and when a search button is clicked, the search keyword is appended to the url (see examples below). Note the keyword may contain any character. Example 1 Search key: whatever you want URL: www.exam...

.NET Regular Expression to split multiple words or phrases

I'm using the code below to take a string and split it up into an array. It will take: Disney Land and make it two separate elements. If the string contains "Disney Land" then it is one element in the array. Works great, however it adds some empty elements to the array each time. So I just iterate over the elements and remove them i...

String method to get unknown value that matches regex from string

Hi, In Java is there a way to extract the value of an unknown subset of a string via a regex. For example in the following string "hello world 1234" I want to be able to extract the value 1234 via the regex [0-9]*. Is there a way to do this? ...

Matching Regular Expression in Javascript and PHP problem...

I can't figure out how to get the same result from my Javscript as I do from my PHP. In particular, Javascript always leaves out the backslashes. Please ignore the random forward and backslashes; I put them there so that I can cover my basis on a windows system or any other system. Output: Input String: "/root\wp-cont ent\@*%'i@$@%$...

How Do You Parse Column Data ?

I am trying to parse a file generated by LGA Tracon that lists the position data for aircraft over a given time frame. The data of interest starts with TRACKING DATA and ends with SST and there are thousands of entries per file. The system generating the file, Common ARTS, is very rigid in its formatting and we can expect the column sp...

Regex to match number or specific string (i.e. "all")

This sounds simple but my regex knowledge is limited. I need an expression to match a decimal number or the string "all", as in a range validator that allows the word all represent the max range. I thought something like this might work: ((^[-+]?\d*\.?\d*)|any) But the above doesn't work for "any". ...