regex

Regex to allow text, some special characters and keep below a specified length

Hi all, I'm trying to create a validation expression that checks the length of an input and allows text and punctuation marks (e.g. , ? ; : ! " £ $ % ) What I have come up with so far is "^\s*(\w\s*){1,2046}\s*$" but this won't allow any punctuation marks. To be honest I'm pretty sketchy in this area so any help would be greatly appre...

find word before second comma with regex

I want to store the word before the second comma in a string. So if the string looks like this: Hello, my name is David, bla bla. I want to set a variable $test = David ...

Number grouping using regexps

Is it possible to do number grouping (e.g., converting the number 1000 to the string "1 000") using one pass with only regular expressions? (I know the boundary between regexp and language facilities are a bit blurred in some systems - listen to your conscience before replying.) Reason why I'm asking: Another dev recently asked me how t...

Java regexp overmatches

I want to replace a single <, but not <<, using a Java regexp (so I'm working with String.replaceAll()). Right now I have ([^<]|^)<([^<]|$) which works in Python, but not Java. I have also tried negative look-around, with something like (?<!<)<(?!<) However, all my current attempts match << as well. Am I doing something wrong? Is t...

How do I know if a regexp has more than one possible match?

I am writing Java code that has to distinguish regular expressions with more than one possible match from regular expressions that have only one possible match. For example: "abc." can have several matches ("abc1", abcf", ...), while "abcd" can only match "abcd". Right now my best idea was to look for all unescaped regexp special cha...

Java: Simple regex question, complete words

Hi, i need a Regex to do this ( catch only real words ): Inputstring: hello,[email protected] Process: String theMagicRegEx = "?????"; String[] arrayvar = asdf.split(theMagicRegEx); Output (arrayvar) should be this: hello sdfsdf yahoo email com Question: What is the value of theMagicRegEx? Thanks a lot ...

Apache rewrite condition and the absence of characters

We have the following mod_rewrite condition/rule but it is returning a 404 error on URLs that merely begin "i" (or "css" for that matter) if they do not equate precisely to our corresponding directories (/i /css etc.) RewriteEngine on RewriteCond $1 !^(index\.php|robots\.txt|/(i|css|design_and_docs|js|test)/*) RewriteRule ^(.*)$ /index....

Best way to read rapidshare API response ?

Hi There, I've started working with the rapidshare.com API. I'm just wondering what is the best way to read the reply from and API call. To be honest I think the API is all over the place. Some replies are comma delimited which is fine. I'm having with problems with the account info response. This is not comma delimited and the fields ...

simple regex for Fred, Jhon, Somelse,

I need regex that will match this Fred, Jhon, Tree, and there could be some spaces between the commas and the words, and between the start of the line and the first word. Can anyone help me with this ? ...

Replacing variable numbers of items... regex?

Ok... I have an unsatisfactory solution to a problem. The problem is I have input like so: {sup 19}F({sup 3}He,t){sup 19}Ne(p){sup 18}F and need output like so: ¹⁹F(³He,t)¹⁹Ne(p)¹⁸F I use a series of replacements first to split each of the {sup xx} sections into {sup x}{sup x} and then use a regex to match each of those and repla...

PHP: Correct regular expression for making every letter left of the first colon lowercase

$value='x-Cem-Date:Wed, 16 Dec 2009 15:42:28 GMT'; Right now I have: $value = preg_replace('/(^.+)(?=:)/e', "strtolower('\\1')", $value); this outputs $value='x-cem-date:wed, 16 dec 2009 15:42:28 GMT'; it should output: $value='x-cem-date:Wed, 16 Dec 2009 15:42:28 GMT'; ...

PHP preg_replace: help me grok (?=:)

In another question, there are the following lines: $value='x-Cem-Date:Wed, 16 Dec 2009 15:42:28 GMT'; $value = preg_replace('/(^.+?)(?=:)/e', "strtolower('\\1')", $value); // yields 'x-cem-date:Wed, 16 Dec 2009 15:42:28 GMT' That (?=:) bit indicates a search for the colon, it has to. But, I don't understand that particular syntax, w...

VIM: How to preserve case for search and replace

Is it possible to do a search and replace in vim that preserves the case of the search term? This was a useful feature in intelliJ that I miss. For instance, something like: :s/[uU]ser/[pP]erson/ (obviously, this doesn't work) Such that: user->person User->Person Another example with multiple characters to preserve: :s/[mM]y[uU]s...

Explain this Regular Expression please

Regular Expressions are a complete void for me. I'm dealing with one right now in TextMate that does what I want it to do...but I don't know WHY it does what I want it to do. /[[:alpha:]]+|( )/(?1::$0)/g This is used in a TextMate snippet and what it does is takes a Label and outputs it as an id name. So if I type "First Name" in the...

Why having both str_replace() and preg_replace()?

I came to know PHP after Perl, so when I first found preg_* function I basically just used those. Later I read that str_replace() is faster when dealing with literal text. So my question is, can't preg_replace() be as efficient as str_replace() when the search pattern does not use special characters? Maybe just analyzing the pattern to c...

c++ boost regex which element was true

The answer to this may be a simple no, but here goes... I'm currently using the boost function regex_match to evaluate a string against a regex value. Instead of just returning T/F, is there a way to find out which element of multiple joined statements evaluated to true? For example: ^a$|^z$|^p$ a --> 0 z --> 1 f --> -1 ...

Regular Expression returning false, why?

Possible Duplicate: Email Validation - Regular Expression I have the following regular expression email validator: @"^(([\w-]+.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]? [0-9]{1,2}|25[0-5]|2[0-4][0-9])." + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]? [0-9]{1,2}...

get word before a :- sign in a string with regex

I need to get the amount before a :- sign. So the string would be: bla bla 120:- And then store only 120 in a variable ...

Mass string replace in python?

Say I have a string that looks like this: str = "The &yquick &cbrown &bfox &Yjumps over the &ulazy dog" You'll notice a lot of locations in the string where there is an ampersand, followed by a character (such as "&y" and "&c"). I need to replace these characters with an appropriate value that I have in a dictionary, like so: dict =...

how to transform a string to an array with # as a delimiter but only the first one?

(only the first # is a delimiter) 50#some message from me to you #1 or #2 into array ( [amount] => 50 [message] => 'some message from me to you #1 or #2' ) ...