regex

Python regular expression slicing

I am trying to get a web page using the following sample code: from urllib import urlopen print urlopen("http://www.php.net/manual/en/function.gettext.php").read() Now I can get the whole web page in a variable. I wanna get a part of the page containing something like this <div class="methodsynopsis dc-description"> <span class="t...

Php Regular Expression repeated characters

I have a string in php like this. $str = "ABCCCDE" //Contains repeated character CCC more than 2 times I want to know if there is any repeated characters more than 2 times using regular expression. Thanks in advance ...

How to match bare urls with regex in PHP?

$bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE); Say,I'm trying to match urls that need to be linkified.The above is too permissive. I want to only match simple urls like http://google.com, but not <a href="http://google.com"&gt;http://google.com&lt;/a&gt;, or <iframe src="http://g...

A way to use RegEx to find a set of filenames paths in a string

Good morning guys Is there a good way to use regular expression in C# in order to find all filenames and their paths within a string variable? For example, if you have this string: string s = @"Hello John these are the files you have to send us today: <file>C:\Development\Projects 2010\Accounting\file20101130.csv</file>, <file>C:\Dev...

Comparison of Regex flavours

I wonder if there is a comparison between the features of various regex metacharacters in various implementations. The sort of thing I am looking for is a table like Language Perl sed grouping ( ) \( \) Languages I am interested in are Perl, Sed Java Javascript ...

RegexKit Category problem

I'm having some trouble using the RegexKit.framework. I've properly integrated it into my project and I want to use the NSString category methods to get an array of matches from a string. Though I have imported the the framework Xcode keeps complaining that "NSString may not respond to '-stringByMatching:'". Do I miss something when work...

php regex - extract all text before certain characters

I am trying to extract publisher information from a string. It comes in various formats such as: John Wiley & Sons (1995), Paperback, 154 pages New York, Crowell [1963] viii, 373 p. illus. 20 cm. New York: Bantam Books, c1990. xx, 444 p. : ill. ; 27 cm. Garden City, N.Y., Doubleday, 1963. 142 p. illus. 22 cm. [1st ed.]...

Regular expression needed for PHP

Can anybody tell me a regular expression to use within some PHP to find the following: <p>&nbsp;</p> with any variation of white space between those tags <p><br/> again with any variation of white space between those tags Any help appreciated, thanks! ...

Internal Error when file does not exist

I want get everything up to the "/" and merge with ".php" works fine, but when the file does not exist I get internal error RewriteRule ([^\/]*) $1.php ...

Ruby or regex to strip excess line breaks

How would you turn this: Dear Fred How are you? Regards John Into this: Dear Fred How are you? Regards John Note: Single and double breaks are allowed, but no more than that. For example, we want to go from: "Dear Fred\n\n\n\nHow are you?\n\n\n\n\n\n\nRegards\nJohn" to "Dear Fred\n\nHow are you?\n\nRegards\nJohn" But...

using regular expressions in ruby to find a string in quotations

I am trying to construct a regex to find a string in ruby str = "foo" I want to be able to stop trying to find the string after it finds the closing quotation mark. I also want to keep the quotation marks so I can output the string I found as: puts "the string is:" + str => the string is: "foo" I am pretty new to using regular expr...

Why does this regex not work: '\([0-9a-zA-z]*\)';

What I'd like to do remove the part of a string that is contained in brackets. So for example be able to go from "Hello (World)" to "Hello". I am using var input2 = '\([0-9a-zA-z]*\)'; as my expression statement, and using regular expressions to match this pattern. Can someone tell me what I'm going wrong? I must be escaping the "(" ...

PHP Array filter regular expressions

Hi all i have an array shown below Array ( [0] => http://api.tweetmeme.com/imagebutton.gif?url=http://mashable.com/2010/09/25/trailmeme/ [1] => http://cdn.mashable.com/wp-content/plugins/wp-digg-this/i/gbuzz-feed.png [2] => http://mashable.com/wp-content/plugins/wp-digg-this/i/fb.jpg [3] => http://mashable.com/wp-cont...

Difficulty with a simple regex for .obj files

I'm trying to parse lines of the form: command arg1[ arg2, ... argn] such as: usemtl weasels or f 1/2/3 4/5/6 7/8/9 Here is my regex: ^(\\w+)(( \\S+)+)$ When I parse the line "usemtl weasels", I get the following capture groups: Match 0: 'usemtl weasels' Match 1: 'usemtl' Match 2: ' weasels' Why the space before the seco...

How can I use regular expressions and javascript to split the following command into tokens:

filter -n ""function(file) { return file.owner == "john"; }"" should be parsed into the following array: [ 'filter', '-n', 'function(file) { return file.owner == "john"; }' ] ...

How to include a minus sign in this regex?

I'm trying to match the following three lines: usemtl ftw kd 1.2 3.2 3.1 v -12.1892 -53.4267 -276.4055 My regex matches the first two: ^(\w+) ((\S+)( \S+)*) *$ I've tried a few variants to match the negative numbers, but they just stop anything from being matched: ^(\w+) (([\S-]+)( [\S-]+)*) *$ ^(\w+) (((\S|-)+)( (\S|-)+)*) *$ ...

How can I capture all nonempty sequences of letters other than cat, dog, fish using a regular expression?

Please explain why the expression makes sense if it is complicated. ...

What's the technical reason for "lookbehind assertion MUST be fixed length" in regex?

For example,the regex below will cause failure reporting lookbehind assertion is not fixed length: #(?<!(?:(?:src)|(?:href))=["\']?)((?:https?|ftp)://[^\s\'"<>()]+)#S Such kind of restriction doesn't exist for lookahead. ...

How can I parse this text using regex (ruby)?

http://services.tvrage.com/tools/quickinfo.php?show=Chuck I'm trying to parse that info, for exmaple, get the Airtime, Airtime@Monday at 08:00 pm I want to get what's after "Airtime@" till the end of the line, to just come out with "Monday at 08:00 pm". How can I do this? ...

Use regular expressions to remove HTML tags in Flex/AS3

Hi, I'm writing a HTML parser in Flex (AS3) and I need to remove some HTML tags that are not needed. For example, I want to remove the divs from this code: <div> <div> <div> <div> <div> <div> <div> ...