regex

regexp get filename from url

url: http://blabla.bl/blabla/ss/sd/filename How to get a filename? ...

complex rewrite rule needed for .htaccess file

I have a lot of simpler rules working on this site so I know mod_rewrite is working. I just can't figure out how to create a rule for this situation. I'm using Joomla CMS and one component in particular is generating awful URLs that duplicate other (pretty) URLs on the site. There is a consistent pattern so I can rewrite the URLs but thi...

how can i obtain pattern string from compiled regexp pattern in python

I have some code like this one: >>> import re >>> p = re.compile('my pattern') >>> print p _sre.SRE_Pattern object at 0x02274380 Is it possible to get string "my pattern" from p variable? ...

Regex: faulty syntax used with preg_replace_callback?

I have borrowed code from this link http://stackoverflow.com/questions/959017/php-regex-templating-find-all-occurrences-of-var to implement a means of applying values to template fiies. This uses the preg_replace_callback() function my preferred method of naming is name1.name2.name3=value, rather than name1_name2_name3=value, but the re...

Preg Replace / Preg Match for href in html link?

Anybody have a regular expression to replace the following code: <a href="originalLink">hi</a> with: <a href="newLink">hi</a> ...

Regex - find all links in a tweet

Hi, My regex is poor and letting me down so some help would be great here. All I want to do is return all the links which appear in a tweet (just a string) - Some examples are: "Great summary http://mytest.com/blog/post.html (#test) "http://mytest.com/blog/post.html (#test) "post: http://mytest.com/blog/post.html" It should also s...

parse tnsnames.ora using grep to extract hostname minus the domain

Hi I have tnsnames.ora file like DB_CONNECTION1= (description= (address= (protocol=tcp) (host=myhost1.mydomain.com) (port=1234) ) (connect_data= (sid=ABCD) (sdu=4321) ) DB_CONNECTION2= (description= (address= (protocol=tcp) (host=myhost2.mydoma...

JavaScript regex - check number of numeric-only matches

I have this regex thanks to another wonderful StackOverflow user /(?:-\d+)*/g I want it to match things like 133-134-454-58819860 12-13-876-1234346 each block (numbers between -'s) could be any length but it will defiantly only be numbers and there will only 4 blocks. But currently it's matching things like -2008 I'm really bad ...

Replacing image src in HTML tags?

I want to use regex to replace src html attributes. The HTML is not malformed and fortunately takes the same form in all the pages in the database - i.e. <img src="http://x.y/z/1.png" /> I have code that works fine if there's only one image in the page. I want to know the best way to replace multiple images, as this one will replace a...

Question about preg_replace in PHP

In PHP what is the difference between using \1 or $1 as $replacement in preg_replace()? They both work and seem to do the exact same thing, but I think I'm missing something here. ...

The Hostname Regex

I'm looking for the regex to validate hostnames. It must completely conform to the standard. Right now, I have ^[0-9a-z]([0-9a-z\-]{0,61}[0-9a-z])?(\.[0-9a-z](0-9a-z\-]{0,61}[0-9a-z])?)*$ but it allows successive hypens and hostnames longer than 255 characters. If the perfect regex is impossible, say so. Edit/Clarification: a Google s...

Regex script remove - Easy

Can anybody help me with a regex I am trying to remove everything between <Script ?????> and </script> I am using asp and visualscript replace(/< script.*?>*?< \/script>/ig, ''); This should work (I think) but it is not working for me, any help would be appreciated! Thanks Update: I have done it like this and it now removes < scr...

In RegEx, how do you find a line that contains no more than 3 unique characters?

Hey guys, I am looping through a large text file and im looking for lines that contain no more than 3 different characters (those characters, however, can be repeated indefinitely). I am assuming the best way to do this would be some sort of regular expression. All help is appreciated. (I am writing the script in PHP, if that helps) ...

regex to get meta keywords

Hi I was hopeing that someone can help me with this regex. I want to match the patern below once to extract meta keywords from a page: .match(/(<meta name=[\"|\']keywords([^\/>]*))/ig); Any ideas will be welcomed ...

How to Specify NOT with Regular Expressions for Words

How to Specify NOT with Regular Expressions for Words I want to filter a list of event names based on a regular expression. I can create a regular express to include (or match) name, but what would be the regular express to exclude (not match) a name? For instance, if I want to include mouse events then the pattern would be "^Mouse". I...

Oracle PL/SQL REGEXP_LIKE / REGEXP_INSTR

Hi, I require a means of checking to see if a string has the following exact pattern within it, i.e.: (P) Examples where this would be true is: 'Test System (P)' Unsure though how to check for cases when the string that doesn't have '(P)', i.e: 'Test System (GUI for Prof)' - in this case, this would be false but I am using REGEXP_...

Regular expression to match C #include file

Hello, I need some help trying to match a C include file with full path like so: #include <stdio.h> -> stdio.h #include "monkey/chicken.h" -> monkey/chicken.h So far I have (adapted from another expression I found): ^\s*\#include\s+(["'<])([^"'<>/\|\b]+)*([">]) But, I'm kind of stuck at this point - it doesn't match in the second ...

Does C or C++ have a standard regex library?

Does it? If yes, where can I get the documentation for it... if not, then which would be the best alternative? ...

Got "two named subpatterns have the same name" when combining 2 regex into one

Hi, I'm trying to combine 2 different regex with the same names into one and got the error message like this: Warning: preg_match(): Compilation failed: two named subpatterns have the same name at offset 276 ... One regex looks like this: '%<div class="artikkelen">[\s\S]*?<h2>(?P<title>[\s\S]*?)</h2>%' The other looks like ...

JavaScript/jQuery method to find base URL from a string

I'm trying to find a relatively easy and reliable method to extract the base URL from a string variable using JavaScript/jQuery. For example, given something like: http://www.sitename.com/article/2009/09/14/this-is-an-article/ I'd like to get: http://www.sitename.com/ Is a regular expression the best bet? If so, what statement could...