regex

Count characters in P keeping non-latin characters

I have a script that counts the characters in each of my comments, excluding any Html Tags. But it doesn't take into account that my comments contain åäöÅÄÖ (swedish letters). So how do I edit this to "exclude" these from the regexp variable? (If the comment is "Hej då!" the result is 6, not 7.) Why I need this is a long story, the pro...

Match text in loops in Ruby

I have to go through the following text and match each of the following, and break them apart into separate records to save to a database. So this text: ESTIMATED MINIMUM CENTRAL PRESSURE 951 MB EYE DIAMETER 12 NM MAX SUSTAINED WINDS 105 KT WITH GUSTS TO 130 KT 64 KT....... 25NE 25SE 25SW 25NW 50 KT....... 60NE 30SE 30SW 60NW 34...

How do I use a variable pattern with preg_match?

I don't know if this is enough data to feed off of, but I have preg_match('/SAMPLETEXT/', $bcurl, $cookie1); and I was wondering if I can make it preg_match($newfunction, $bcurl, $cookie1); but when I do, I get this error "Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in". How ...

Regular Expression Works In One Script and Doesn't In Another

I've stumbled across an interesting bug in PHP. Basically I have a regular expression seen below which works fine in one script (Script A) but fails to work when put into a class and used in a script (Script B). I have tested this script on PHP 5.3, and 5.2. Script A: http://iamdb.googlecode.com/svn/trunk/testing.php Script B: Class ...

Java: Regex on byte array

I want to do something like a regular expression in Java, but on a byte array instead of a String For example, let's say I want to delete from the array all continuous segments of 0's longer than 3 bytes byte a[] = {1,2,3,0,1,2,3,0,0,0,0,4}; byte r[] = magic(a); System.out.println(r); result {1,2,3,0,1,2,3,4} Is there something th...

Matching multiline Patterns

I want to use greasemonkey to scrape wiki data from Last.fm (this is not possible with their REST api). I can grab the page fine with GM_xmlhttpRequest(), and it is returning properly. I do not want to use a DOM processor to process the whole page, since I only want a small chunk, so I'm using regular expressions. The wiki data is in t...

Validate string without special characters

i have a problem. i what to get info about my string have ordre chater in ( a-z A-Z 0-9 and - _ ) if my string have ordre its return false or not return true. i hob i can get help to this problem. ...

How can I inject PHP code at certain points of a string variable?

I have a class that stores paths to CSS and Javascript files in arrays. This class also compiles my final page HTML output (which is stored in an $output variable). I want to loop through my $css and $js arrays and inject HTML at specific points in $output. The CSS files would need to go right before </head> and the JS files would need t...

Verify CSV against given format

I am expecting users to upload a CSV file of max size 1MB to a web form that should fit a given format similar to: "<String>","<String>",<Int>,<Float> That will be processed later. I would like to verify the file fits a specified format so that the program that shall later use the file doesnt receive unexpected input and that there ar...

Generating HTML (i.e. br and p tags) from plaintext in C++

I've got a bunch of text like this: foo bar baz What's likely to be the most efficient way in C++ of transforming that to this: <p>foo<br />bar</p> <p>baz</p> for large(ish) quantities of text (up to 8000 characters). I'm happy to use boost's regex_replace, but I was wondering if string searching for \n\n might be more efficient?...

How to remove text in brackets using a regular expression

Hi there, I'm looking for a regular expression which will perform the following: INPUT: User Name ([email protected]) OUTPUT: User Name What would be the best way to achieve this? Using regular expression to extract the text within the brackets and replacing this and any )( characters? Any help would be appreciated, Thanks ...

Regular expression problem

Hi, ^([0-9]*[1-9][0-9]*(\.[0-9]+)?|[0]+\.[0-9]*[1-9][0-9]*)$ I don't know regular expression well. Above regular expression does not allow input .2 .but it allows all other decimals like 0.2 , 0.02 etc . I need to make this expression allow the number like .2 ,.06 , etc..... ...

How can I tokenize this with a regex?

Suppose I have strings like the following : OneTwo ThreeFour AnotherString DVDPlayer CDPlayer I know how to tokenize the camel-case ones, except the "DVDPlayer" and "CDPlayer". I know I could tokenize them manually, but maybe you can show me a regex that can handle all the cases? EDIT: the expected tokens are : OneTwo -> One Two ......

Unescaped "." still matches when used in a negation group.

I made, what I believed to be, an error in a regular expression in Java recently but when I test my code I don't get the error I expect. The expression I created was meant to replace a password in a string that I received from another source. The pattern I used went along the lines of: "password: [^\\s.]*", the idea being that it would ...

grab specific parts of a filename with jquery

I need to grab two chunks of a string to obtain the values. I've wrapped them in curly braces for demo purposes. I assume I need to use a bit of regex for this? I'm not asking for someone to spoonfeed me the code, but I'm struggling to figure out how to match more than one part of a string. Once I understand how to do this the world is m...

Search for embedded email and phone numbers

I need to use a javascript form validation routine to scan various input text fields for embedded phone numbers and email addresses. This is for a classifieds system that is free to post but 'pay to connect' with buyers, so the intent is to prevent (as much as possible) the ability for users (those posting the ad) from simply embedding t...

ModRewrite Split Issue

This is a complicated one which I hope has a simple answer... RewriteRule ^category/([^.]+)/([0-9]+)/([^.]+)/([0-9]+) category.php?c_id=$2&filters=$3&_p=$4&name=$1 This rule would pick up category/kitchen/10/0-0-0-0-0-0-0-0/1 with the following get vals: category.php?c_id=10&filters=0-0-0-0-0-0-0-0&_p=1&name=kitchen The reason fil...

Javascript Regular Expressions Lookbehind Failing

Hi folks, I am hoping that this will have a pretty quick and simple answer. I am using regular-expressions.info to help me get the right regular expression to turn URL-encoded, ISO-8859-1 pound sign ("%A3"), into a URL-encoded UTF-8 pound sign ("%C2%A3"). In other words I just want to swap %A3 with %C2%A3, when the %A3 is not already p...

Regex for a specific url pattern

In C#, how would I capture the integer value in the URL like: /someBlah/a/3434/b/232/999.aspx I need to get the 999 value from the above url. The url HAS to have the /someBlah/ in it. All other values like a/3434/b/232/ can be any character/number. Do I have escape for the '/' ? ...

Why does this simple email address validation not work for me?

Here is my code; I got the reg ex from a PHP book. function is_email($email) { // Checks for proper email format if (! preg_match( '/^[A-Za-z0-9!#$%&\'*+-/=?^_`{|}~]+@[A-Za-z0-9-]+(\.[AZa-z0-9-]+)+[A-Za-z]$/', $email)) { return false; } else { return true; } } Now to test to see if the email is valid I am using: if (is_email(...