regex

jQuery and regex for adding icons to specific links?!

I'm using jQuery to add icons to specific links, e.g. a myspace icon for sites starting with http://myspace.com etc. However, I can't figure out how to use regular expressions (if that's even possible here), to make jQuery recognize the link either with or without "www." (I'm very bad at regular expressions in general). Here are two e...

Determining whether values can potentially match a regular expression, given more input

I am currently writing an application in JavaScript where I'm matching input to regular expressions, but I also need to find a way how to match strings to parts of the regular expressions. For example: var invalid = "x", potentially = "g", valid = "ggg", gReg = /^ggg$/; gReg.test(invalid); //returns false (correct) gReg.t...

One regular expression to match parts in various positions

Hi all, I'm trying to parse a DSN (from a Symfony application) using regular expressions, in order to link with a secondary application, but using the same database. The DSN I currently have is: mysql:dbname=my_db_name;host=localhost with a regex of: /^(\w+):(dbname=(\w+))?;?(host=(\w+))?/ (using preg_match()). This matches OK, ...

regular expression for matching number and spaces.

Hi all i want to create a regular expression which will allow only spaces and number.. And how can i check this with PHP? Thanks in advance Avinash ...

Apache complex regex crashing with 500 error

I have been working with an existing website out company has running until I finish developing the new site. I've been asked to add some additional functionality to booking pages that will automatically set a booking button based on passed parameters. The existing working regex is as follows: RewriteRule ^.+-(\d+)\.accommodation$ prop...

How do I determine whether ruby can fork without excessive use of regexp?

Is it possible to determine whether the implementation of ruby you're running on is capable of supporting fork, without running a regex against RUBY_PLATFORM that'll expand until it summons Cthulhu? (Related question: Ruby - How can I find out on which system my program is running?) Edit: I tried Marc-Andre's suggestion. It doesn't wor...

JavaScript (jQuery) Regular Expression for searching through an array

First and foremost, I do not know RegEx but am trying to piece something together to make this work. Just wanted you to be forewarned. ;) Anyways, I'm trying to create a regular expression to take a word from an array and see if it matches a word in another array. I only want the search to return true if the keyword array string contain...

Java RegExp ViewState

I am porting some functionality from a C++ application to java. This involves reading non-modifiable data files that contain regular expressions. A lot of the data files contain regular expressions that look similar to the following: (?<=id="VIEWSTATE".*?value=").*?(?=") These regular expressions produce the following error: "Look-...

Regex: Matching a space-joined list of words, excluding last whitespace

How would I match a space separated list of words followed by whitespace and some optional numbers? I have this: >>> import re >>> m = re.match('(?P<words>(\S+\s+)+)(?P<num>\d+)?\r\n', 'Foo Bar 12345\r\n') >>> m.groupdict() {'num': '12345', 'words': 'Foo Bar '} I'd like the words group to not include the last whitespace(s) but I can...

Regular Expression Question

I'm trying to use regular expression to extract the comments in the heading of a file. For example, the source code may look like: //This is an example file. //Please help me. #include "test.h" int main() //main function { ... } What I want to extract from the code are the first two lines, i.e. //This is an example file. //Please...

Regexp help - converting video code to wordpress short tag

Hi, I'm trying to convert a camtasia html/javascript video embed code to a wordpress flowplayer shortcode. The original code is as follows: <p>The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Adobe Flash Player. If you are you using a browser with JavaScript disabled plea...

regular expressions - my expression

I've got (To) [a-z]+ as regular expression and I've got sentence: To kot dziki pies. And If I compile it I will retrieve To kot. So what can I do to retrieve only word after (only kot) "To" instead of "To kot"? ...

javascript regex to extract a word from middle of 6 sentence

i have a string like following: Assigned to ram on 2010-04-22 12:30:13.0 i need to extract the third word (ram). I tried the below regex, its not working. /\s[a-zA-Z]*\s/ any help to fix this would be greatly appreciated. ...

javascript match isn't greedy

given text:1,0397,030 followed by nothing or any number of characters not in the set [,0-9] why is my regex not being greedy enough? Javascript's regex is supposed to be greedy by default, right? but text.match('[,0-9]+'); pulls back 1,0397 instead of 1,0397,030 var matches = shortInput.match('[0-9]+[,0-9]*[0-9]*'); works. This is in...

How to regex match a string of alnums and hyphens, but which doesn't begin or end with a hyphen?

I have some code validating a string of 1 to 32 characters, which may contain only alpha-numerics and hyphens ('-') but may not begin or end with a hyphen. I'm using PCRE regular expressions & PHP (albeit the PHP part is not really important in this case). Right now the pseudo-code looks like this: if (match("/^[\p{L}0-9][\p{L}0-9-]{...

Regex: Find/Replace All Substrings Without a Given String Before?

I need to find all strings without a given string before it. For Instance: Find: "someValue" **All results with "function(" before them should be ignored The Visual Studio regular expression would find this: value = someValue And Ignore something looking like this: function(someValue) What is the best way to go about this? Th...

PHP PCRE differences on testing and hosting servers

Hi all, I've got the following regular expression that works fine on my testing server, but just returns an empty string on my hosted server. $text = preg_replace('~[^\\pL\d]+~u', $use, $text); Now I'm pretty sure this comes down to the hosting server version of PCRE not being compiled with Unicode property support enabled. The diffe...

How can I extract a string between matching braces in Perl?

My input file is as below : HEADER {ABC|*|DEF {GHI 0 1 0} {{Points {}}}} {ABC|*|DEF {GHI 0 2 0} {{Points {}}}} {ABC|*|XYZ:abc:def {GHI 0 22 0} {{Points {{F1 1.1} {F2 1.2} {F3 1.3} {F4 1.4}}}}} {ABC|*|XYZ:ghi:jkl {JKL 0 372 0} {{Points {}}}} {ABC|*|XYZ:mno:pqr {GHI 0 34 0} {{Points {}}}} { ABC|*|XYZ:abc:pqr {GHI 0 68 0} ...

A regex to match a comma that isn't surrounded by quotes.

I'm using Clojure, so this is in the context of Java regexes. Here is an example string: {:a "ab,cd, efg", :b "ab,def, egf,", :c "Conjecture"} The important bits are the commas after each string. I'd like to be able to replace them with newline characters with Java's replaceAll method. A regex that will match any comma that is not su...

Multiply with find and replace

Can regular expressions be used to perform arithmetic? Such as find all numbers in a file and multiply them by a scalar value. ...