regex

Help in Regex - Match YouTube Url

I have the following string for example: abcba"c"bacba"fbaf"gdsfgafa"http://www.youtube.com/watch?v=0eLoApO7wrs"gsg How can I extract the youtube url from this string? ...

How can i match this with ruby regex {{article | image}}

It also needs to work for {{ article |image}} or any other withespace combination inside the double braces. ...

Add a word to the ending of every third sentence.

Hello I'm creating a "fun-translator", and I'm trying to add a word to the end of every third sentence or so. It gets another page HTML code and translate it into teen language. But I want to add a word to every third sentence. I've been using this line for now: $str = preg_replace_callback('{<.*?[^>]*>([æøåÆØÅ !,\w\d\-\(\)]+)([<|\s|!|...

help with regular pattern

this pattern will get me all files that begin with a nr and it works perfectly. glob("path_to_dir/^[0-9]*"); but i want to have a pattern that gets me all files that ends with _thumbnail regardless file extension. eg. 1.jpg 1_thumbnail.jpg 2.jpg 2_thumbnail.png will get me 1_thumbnail.jpg 2_thumbnail.png i have tried: glob("pa...

get number from file with regexp?

ive got files named 1234_crob.jpg 1234.jpg 2323_örja.bmp 2323.bmp etc how can i just retrieve numbers eg. 1234 and 2323? thanks in advance ...

A regular expression to exclude a word/string

Hello, I have a regular expression as follows: ^/[a-z0-9]+$ This matches strings such as /hello or /hello123. However, I would like it to exclude a couple of string values such as /ignoreme and /ignoreme2. I've tried a few variants but can't seem to get any to work! My latest feeble attempt was ^/(((?!ignoreme)|(?!ignoreme2))[a-...

Preg_match_all: Regex to extract block of data

Would somebody care to help me out with a preg_match_all Regex? I need to extract from a block that looks like this: (arbitrary data) alt=BAUSTEIN^550^^transparent^transparent^null^null^(...base64 encoded data...) ^ (arbitrary data) alt=BAUSTEIN^550^^transparent^transparent^null^null^(...base64 encoded data...) ^ all base64 encoded b...

Need help with hard regex

I need a regex that checks if a string only contain letters(a-z) and that the first letter is uppercase, you cant have 2 letters in a word uppercase Like: THomas or THomAS but Thomas Anderson (Thomas anderson too) would be valid look: The Magician Of The Elfs would be valid but not ThE MaGiCiAN oF ThE ELFS if (!preg_match("??", $name)...

testing for "EndsWith" efficiently with a Regex

I need to build a Regex (.NET syntax) to determine if a string ends with a specific value. Specifically I need to test whether a file has a specific extension (or set of extensions). The code I'm trying to fix was using: .*\.(png|jpg|gif)$ which is hideously slow for failed matches in my scenario (presumably due to the backtracking....

Python raw strings and unicode : how to use Web input as regexp patterns ?

EDIT : This question doesn't really make sense once you have picked up what the "r" flag means. More details here. For people looking for a quick anwser, I added on below. If I enter a regexp manually in a Python script, I can use 4 combinations of flags for my pattern strings : p1 = "pattern" p2 = u"pattern" p3 = r"pattern" p4 = ru"p...

Regex for removing whitespace

def remove_whitespaces(value): "Remove all whitespaces" p = re.compile(r'\s+') return p.sub(' ', value) The above code strips tags but doesn't remove "all" whitespaces from the value. Thanks ...

Ruby gsub problem when using backreference and hashes.

The following code defines a hash with regular expressions (keys) and replacements (values). Then it iterates over the hash and replaces the string accordingly. Simple string substitution works well, but when I need to compute the resut before substituting it (the case of years to days change), it does not. And it is key that the hash ...

Regex replace - how to replace same pattern in multiple places with different strings?

Hi, I have a peculiar problem..! I have a string with some constant value at multiple paces. For example consider the following sting. string tmpStr = "Hello _tmp_ how is _tmp_ this possible _tmp_ in C#...?" Now i want to replace each of the tmp in the string with values that are stored in an array, first tmp holds array[0], second t...

How to remove a string?

I have an string like this: string s1 = "abc,tom,--Abc, tyu,--ghh"; This string is dynamic, and I need to remove all substrings starting with "--". Output for the example string: s1 = "abc,tom, tyu"; How can I remove these substrings? ...

Why doesn't my Perl regex match what I think it should?

Hi, I tried the following code snippet from Robert's Perl tutorial (link text): > $_='My email address is > <[email protected]>.'; > > print "Found it ! :$1:" if /(<*>)/i; When I ran it, the output was: Found it ! :>: However, shouldn't the output be, Found it ! :m>: since 'm' matches "0 or more '<' i.e the '<*' p...

help with glob regexp

would be nice if someone could give me a regexp pattern for glob for getting below filenames: 1.jpg // this file 1_thumb.jpg 2.png // this file 2_thumb.png etc... just returning the files without "_thumb". cause i got this regexp: $numericalFiles = glob("$this->path/*_thumb.*"); and that give me all with "_thumb." thanks ...

Regex Hour:Minute (till 31:59)

I need to identify a hour in a string in a Regex. The rules are the following: The hour is in the format of %m or %h:%m (by %x I mean xx or x); The hour should be till 31:59; Should NOT pass strings like 000, 25:545; :12; So, my actual variant of Regex is (with ExplicitCapture option, I verify it here): ((?<hours>([012]*[0-9])|([3...

Get content from table with id. Regex

I need to sort a html string so I get the content I need. Now I need to loop through the tr's in a table that got an ID. I could really need some help to get this regex going. Appriciate all help I can get ...

split version using Regexp

Hi All, I have a version like this “5.3.08.01”, I want to split this version string into four so that each digit get assigned to variables, means it should be like this: A= 5 B=3 C=08 D=01 I tried doing like this pattern="(\d*).(\d*).(\d*).(\d*)" above expression gives me first digit “5”, now how to get rest of the digits? Can an...

Modifying regex group priority

I have the following Regex: Regex regex = new Regex(@"(?<g1>a?)(?<g2>a?)(?<g3>b?)(?<g4>b?)"); and a string string str = @"ab"; When applying this regex to the string I get g1 -> "a", g2 -> "", g3 -> "b", g4 -> "" Is it possible to modify this regex to get g1 -> "a", g2 -> "", g3 -> "", g4 -> "b"? That is I want to have higher pri...