regex

Retrieving part of a string using jQuery / JavaScript

I know how I would achieve this using PHP, but with jQuery / JavaScript I'm not sure how to, here's the string I'm dealing with (It's the name attribute from a input element): Field[0][some_random_text] I want to retrieve the value some_random_text and slap it in a variable, I guess I would usually use regex to accomplish this task bu...

regex && logical condition (telephone numbers in Sweden)

8, 10, 12, 981 (few area codes in Sweden). Total phone number can be 10 or 11 (digits only) If 8 + 9 or 10 digits if 981 + 7 or 8 digits Can this be done in regex? something like that ..hm (8|10|12)\d{n} => Total Length 10 or 11 ...

Change Password Control RegEx validating oddly in IE 7 only

I'm using the Asp.net change password control in my application and all seems to be find and dandy until a user tells me she has a problem meeting the strength requirements when changing her password. Looking into this, she is using IE 7 and no matter what she puts in, the validation fails (and ONLY in IE 7. Firefox, IE 8, Chrome etc. al...

Scite Lua - escaping right bracket in regex?

Hi all, Bumped into a somewhat weird problem... I want to turn the string: a\left(b_{d}\right) into a \left( b_{d} \right) in Scite using a Lua script. So, I made the following Lua script for Scite: function SpaceTexEquations() editor:BeginUndoAction() local sel = editor:GetSelText() local cln3 = string.gsub(sel, ...

Intelligencia URL ReWriter mapping with regex

I am using the Intelligencia URL rewriter in my asp.net web application. I use the web.config mappings I'm trying to map the following url: www.mydomain.com/product-deals/manufacturer-model_PRODUCTId.aspx To: www.mydomain.com/ProductInfo.aspx?productID=xxx obviously in the above example, xxx is replaced from the "productId"...

PHP Key name array

I have an array $data fruit => apple, seat => sofa, etc. I want to loop through so that each key becomes type_key[0]['value'] so eg type_fruit[0]['value'] => apple, type_seat[0]['value'] => sofa, and what I thought would do this, namely foreach ($data as $key => $value) { # Create a new, renamed, key. $array[...

How can I modify complex command-line argument strings in Perl?

I have a command line that I'm trying to modify to remove some of the arguments. What makes this complex is that I can have nested arguments. Say that I have this: $cmdline = "-a -xyz -a- -b -xyz -b- -a -xyz -a-" I have three different -xyz flags that are to be interpreted in two different contexts. One is the -a context and the othe...

String parsing help

I have a string like the following: $string = " <paragraph>apples are red...</paragraph> <paragraph>john is a boy..</paragraph> <paragraph>this is dummy text......</paragraph> "; I would like to split this string into an array contanining the text found between the <paragraph></paragraph> tags. E.g something like this: $string = " <p...

Python code to use a regular expression to make sure a string is alphanumeric plus . - _

Hi, I looked and searched and couldn't find what I needed although I think it should be simple (if you have any Python experience, which I don't). Given a string, I want to verify, in Python, that it contains ONLY alphanumeric characters: a-zA-Z0-9 and . _ - examples: Accepted: bill-gates Steve_Jobs Micro.soft Rejected: Bill...

Linking Boost to my C++ project in Eclipse

I'm trying to get the Boost library working in my C++ projects in Eclipse. I can successfully build when using header-only libraries in Boost such as the example simple program in the "Getting Started" guide using the lambda header. I cannot get my project to successfully link to the regex Boost library as shown later in the guide. Unde...

Create a permalink with JavaScript

I have a textbox where a user puts a string like this: "hello world! I think that __i__ am awesome (yes I am!)" I need to create a correct URL like this: hello-world-i-think-that-i-am-awesome-yes-i-am How can it be done using regular expressions? Also, is it possible to do it with Greek (for example)? "Γεια σου κόσμε" turns to ...

How to check if string is a valid XML element name?

I need a regex or a function in PHP that will validate a string to be a good XML element name. Form w3schools: XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names cannot start with a number or punctuation character Names cannot start with the letters xml (or XML, ...

Regular Expressions: RegEx for determining valid PHP class property names?

I am using PHP's magic __set and __get methods to access a private array in a class. Use of the class can include "setting" new properties as well as using existing ones. I want to make sure the property names created or requested (i.e. $myObj->FakeProperty) are valid according to the following rules: Property names must begin with eit...

Using sed and/or awk, how can do a sed swap on all text in a file until I see a line matching a regex?

How can I do a sed regex swap on all text that preceed a line matching a regex. e.g. How can I do a swap like this s/foo/bar/g for all text that precedes the first point this regex matches: m/baz/ I don't want to use positive/negative look ahead/behind in my sed regex, because those are really expensive operations on big files. ...

Regular expressions and matching URLs with metacharacters

I'm having trouble finding a regular expression that matches the following String. Korben;http://feeds.feedburner.com/KorbensBlog-UpgradeYourMind?format=xml;1 One problem is escaping the question mark. Java's pattern matcher doesn't seem to accept \? as a valid escape sequence but it also fails to work with the tester at myregexp.com....

How to make this .htaccess rule case insensitive?

This is a rule in my .htaccess # those CSV files are under the DOCROOT ... so let's hide 'em <FilesMatch "\.CSV$"> Order Allow,Deny Deny from all </FilesMatch> I've noticed however that if there is a file with a lowercase or mixed case extension of CSV, it will be ignored by the rule and displayed. How do I make this case insensiti...

What is the MM/DD/YYYY regular expression and how do I use it in php?

I found the regular expression for MM/DD/YYYY at http://www.regular-expressions.info/regexbuddy/datemmddyyyy.html but I don't think I am using it correctly. Here's my code: $date_regex = '(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d'; $test_date = '03/22/2010'; if(preg_match($date_regex, $test_date)) { echo 'this d...

regex count in single match

I want to check if string doesn't have more than 5 numbers. I can do it this way: Matcher matcher = Pattern.compile("\\d").matcher(val); i = 0; while (matcher.find()) { i++; } However I would like to do it without while (because we are using regex validation framework). I want to be able to match strings like A2sad..3f,3,sdasad...

How can I use JavaScript to match a string inside the current URL of the window I am in?

Hi, I have used the excellent gskinner.com/RegExr/ tool to test my string matching regex but I cannot figure out how to implement this into my JavaScript file to return true or false. The code I have is as follows: ^(http:)\/\/(.+\.)?(stackoverflow)\. on a url such as http://stackoverflow.com/questions/ask this would match (accordin...

How do I replace part of a string in C#?

Supposed I have the following string: string str = "<tag>text</tag>"; And I would like to change 'tag' to 'newTag' so the result would be: "<newTag>text</newTag>" What is the best way to do it? I tried to search for <[/]*tag> but then I don't know how to keep the optional [/] in my result... ...