regex

How to enter digits to a certain number

I want to enter only digits in a textbox with the following condition maximum 3 digits maximum from 0 to 250..so 251 should not be accepted. I have written the following code till now..how to take the other conditions too this.value.match(/[^0-9]/g) ...

Get element by id via regex jQuery

Html element contains complex & unique id, composed from namespace as prefix and incremented index - as postfix. I try do it with wildcard expression for id. If to use simple way without namespace, that it works fine: $j("[id*=service_selected_]").click(function(){ ... In order to keep uniqueness,i need provide namespace part within...

Boost.Regex oddity

Hi, Does anyone have any idea why the following code would output "no match"? boost::regex r(".*\\."); std::string s("app.test"); if (boost::regex_match(s, r)) std::cout << "match" << std::endl; else std::cout << "no match" << std::endl; ...

How can I invert a regular expression in JavaScript?

I have a string A and want to test if another string B is not part of it. This is a very simple regex whose result can be inverted afterwards. I could do: /foobar/.test('[email protected]') and invert it afterwards, like this: !(/foobar/).test('[email protected]') The problem I have is, that I need to do it within the regular expression ...

Regular Expression vs XML Functions in PHP

Hiya, I currently do alot of data parsing, and have toyed with PHP functions for XML such as simple XML and a few others here and there. But there always seems to be some sort of issue with dealing with them, mainly due to the way the data is presented. The most reliable way i have found is to always just simply use preg_match_all a...

Simple C# regex

I have a regex I need to match against a path like so: "C:\Documents and Settings\User\My Documents\ScanSnap\382893.pd~". I need a regex that matches all paths except those ending in '~' or '.dat'. The problem I am having is that I don't understand how to match and negate the exact string '.dat' and only at the end of the path. i.e. I...

Remove whitespace and line breaks between HTML elements using jQuery

Using jQuery, I'd like to remove the whitespace and line breaks between HTML tags. var widgetHTML = ' <div id="widget"> <h2>Widget</h2><p>Hi.</p> </div>'; Should be: alert(widgetHTML); // <div id="widget"><h2>Widget</h2><p>Hi.</p></div> I think the pattern I will need is: >[\s]*< Can this be accomplished without...

groovy list indexOf

If I have a list with following elements list[0] = "blach blah blah" list[1] = "SELECT something" list[2] = "some more text" list[3] = "some more text" How can I find the index of where the string starts with SELECT. I can do list.indexOf("SELECT something"); But this is a dynamic list. SELECT something wont always be SELECT someth...

Regex ignore everything between 2 words

Hi, I have some strings to check against a Regex pattern. Here is the regex: apple(?!( ?not)).*?inc(\.|luded)? string 1: "banana, rotten apple not included" - does not give me a match which is what I want. string 2: "banana, rotten apple included" - produces a match which is what I want But if I have a string like... "banana, rott...

python regular expression

Hi all, a question about python regular expression. I would like to match a div block like <div class="leftTail"><ul class="hotnews">any news stuff</ul></div> I was thinking a pattern like p = re.compile(r'<div\s+class=\"leftTail\">[^(div)]+</div>') but it seems not working properly another pattern p = re.compile(r'<div\s+class...

Remove &#xA; from String in .net

Hello, I have a string with &#xA in it the regex: string value = Regex.Replace(textNode.Value, @"\s+", " "); value = value.Replace(" ", ""); value = Regex.Replace(value, @"\&#xA", ""); value = value.Replace("\n", ""); didn't remove it. How do I go about removing &#xA? Note: It did function as a newline when added to a textbox. T...

Perl's Regular Expression in a Tibetan Script

I am trying to remove/delete the second last character of a Tibetan script, as shown below (character in following example are of English): $char = "ti.be.tan.|"; So I want to remove the "second last" character "." I tried in following way with my few knowledge of RE: $char =~ s/.|$/|/g; $char =~ s/[.|]$/|/g; $char = tr/.|//d; ...

Filter user input (paragraph) for links + smileys

Hello, I am looking at some sort of existing filter which can sanitize the user input to avoid XSS. Probably I can use htmlspecialchars for that. But at the same time I want to be able to parse all links (should match a.com, www.a.com and http://www.a.com and if it is http://www.aaaaaaaaaaaaaaaaaaaaaaaaaa.com then it should display it a...

Weird backslash substitution in Ruby

I don't understand this Ruby code: >> puts '\\ <- single backslash' # \ <- single backslash >> puts '\\ <- 2x a, because 2 backslashes get replaced'.sub(/\\/, 'aa') # aa <- 2x a, because two backslashes get replaced so far, all as expected. but if we search for 1 with /\\/, and replace with 2, encoded by '\\\\', why do we get this: ...

RewriteCond match for certain Query param/value pair

I have to do a redirect to another host if a certain parameter/value pair is in the querystring. So far I have RewriteCond %{REQUEST_URI}?%{QUERY_STRING} [&\?]abc=23&? RewriteRule ^(.*)$ http://anotherserver.com/$1 [R,NC,L] that works for /index.php?id=95&abc=23 and /index.php?abc=23&id=95 and /index.php?id=95&abc=23&bla=123 but ...

Making sure a url parameter is not present, using regex

I need 2 regular expressions that I will use in MySQL OK if one of the url parameters equals something (e.g page_id=5) I came up with this: ^https?:.*[?&]page_id=5([#&].*)?$ OK if a certain parameter is not present in the url (e.g do not match [?&]page_id=) This is the one I need help with. This functionality is part of a bigger pro...

ignore case with regular expression

I have created a CLR in a SQL server 2005 database. It is a simple regular expression user defined function that will check if a pattern exists in the string I pass into the function. The dot net code I use in the CLR is shown below: Return System.Text.RegularExpressions.Regex.IsMatch("Input", "pattern") This returns a bit value of ...

How can I insert into Yahoo! Pipes feed titles?

This query concerns Yahoo Pipes only. I want to search for a series of characters in a feed title, and when I've found it, I want to insert some text. Yahoo Pipe's regex module allows you to search and replace, but I don't want to search and replace, only search and insert. Does anybody know whether this is possible? ...

filter_var versus preg_match

Morning all I'm converting a site that I'm working on to be compliant with the latest version of PHP, so I'm going through and replacing all instances of ereg with their non-depreciated equivalent. However I was told about a handy built-in function with PHP called filter_var. What my question is, is would it make sense to go with filte...

Regex named group problem C#

I'm trying to write a regex with named captures in C# to parse cron jobs. The problem, however, is that both using single quote and bracket named capture groups the values return blank. For example, with the input */15 * * * * * http://www.google.com/ this code: Regex cronRe = new Regex(@"(?<minutes>[\d\*\-,]+) (?<hours>[\d\*\-,]+...