regex

regex matching image url with spaces

I need to match a image url like this: http://site.com/site.com/files/images/img (5).jpg Something like this works fine: .replace(/(http:\/\/([ \S]+\.(jpg|png|gif)))/ig, "<div style=\"background: url($1)\"></div>") Except if I have something like this: http://site.com/site.com/files/audio/audiofile.mp3 http://site.com/site.com/f...

How can I strip HTML in a string using Perl?

Is there anyway easier than this to strip HTML from a string using Perl? $Error_Msg =~ s|<b>||ig; $Error_Msg =~ s|</b>||ig; $Error_Msg =~ s|<h1>||ig; $Error_Msg =~ s|</h1>||ig; $Error_Msg =~ s|<br>||ig; I would appreicate both a slimmed down regular expression, e.g. something like this: $Error_Msg =~ s|</?[b|h1|br]>||ig; Is there a...

Given an RE, derive the largest substring match

I'm looking for a bit of code that will: Given regular expression E, derive the longest string X such that for every S, X is a substring of S iff S will match E examples: E = "a", X = "a" E = "^a$", X = "a" E = "a(b|c)", X = "a" E = "[ab]", X = "" context: I want to match some regular expressions against a data store that only sup...

Javascript regex multiline flag doesn't work

I wrote a regex to fetch string from html, but it seems the multiline flag doesn't work. this is my pattern and I want to get the text in h1 tag. var pattern= /<div class="box-content-5">.*<h1>([^<]+?)<\/h1>/mi m = html.search(pattern); return m[1]; I created a string to test it. When the string contains "\n" the result is always nul...

How to search word inside single line using regular expression

string patname ="enter pat name"; patname = "text"; patname = " text pat"; Hi, I want to search "pat" in the above statement using regular expression of visual studio. I tried using Pat{([^a-zA-Z]|$)} this , but it will also search the 2nd line which i really don't want. I want pat to be search inside a string value which starts from "...

Validation of email addresses (ASP.NET)

I have a asp.net web form where i can can enter an email address. i need to validate that field with email addresses ONLYin the below pettern : [email protected] [email protected] [email protected] Please help ...

What is the difference between \1 and $1 in a Perl regex?

What is the difference of doing \1 as opposed to $1 if any, or are they interchangeable in all situations. Example: s/([a-z]+),afklol/$1,bck/; #against s/([a-z]+),afklol/\1,bck/; They both give the same result but is there any difference? ...

XSLT Replace function not found

I am writing an XSLT transformation in which I wish to use the Replace function to do a regex match and replace. However, Visual Studio 2008 reports that 'replace()' is an unknown XSLT function. The bit of code itself is: <xsl:otherwise> <td style="border: solid 1px black; background-color:#00CC66;"> <xsl:variable...

Using the star sign in grep

I am trying to search for the substring "abc" in a specific file in linux/bash So I do: grep '*abc*' myFile It returns nothing. But if I do: grep 'abc' myFile It returns matches correctly. Now, this is not a problem for me. But what if I want to grep for a more complex string, say *abc * def * How would I accomplish it using ...

two regex patterns, can they be one?

I have two regular expressions that I use to validate Colorado driver's license formats. [0-9]{2}[-][0-9]{3}[-][0-9]{4} and [0-9]{9} We have to allow for only 9 digits but the user is free to enter it in as 123456789 or 12-345-6789. Is there a way I can combine these into one? Like a regex conditional statement of sorts? Right n...

How can I split a string if it is a MS-DOS type path OR Unix type path?

I have a string that represents a path to a directory. I want split the string if it is a unix type path or a ms-dos type path. How can this be done? For example: <?php $a = some_path1/some_path2/some_path3; // unix type path $b = some_path1\some_path2\some_path3; // MS-DOS type path $foo = preg_split("something", $a); // what rege...

How, using .NET RegEx, do I parse an HTML file and find 1. External links. 2. Internal links.

I am writing a program that will help me find out sites are my competitors linking to. In order to do that, I am writing a program that will parse an HTML file, and will produce 2 lists: internal links and external links. I will use the internal links to further crawl the website, and the external links are actually what I am looking f...

Regex AND'ing

I have to two strings that I want to match everything that doesn't equal them, the first string can be followed by a number of characters. I tried something like this, negating two ors and negating that result. ?!(?!^.*[^Factory]$|?![^AppName]) Any ideas? ...

Detect URLs in a string and wrap with "<a href..." tag

Hi, I am looking to write something that seems like it should be easy enough, but for whatever reason I'm having a tough time getting my head around it. I am looking to write a python function that, when passed a string, will pass that string back with HTML encoding around URLs. unencoded_string = "This is a link - http://google.com" ...

Java regex split

I have some data formated like the following 2009.07.02 02:20:14 40.3727 28.2330 6.4 2.6 -.- -.- BANDIRMA-BALIKESIR 2009.07.02 01:38:34 38.3353 38.8157 3.5 2.7 -.- -.- KALE (MALATYA) 2009.07.02 00:10:28 38.8838 26.9328 3.0 3.0 -.- -.- CANDARLI KÖRFEZI (EGE DENIZI) 2009.07.01 23:3...

Regex to change spaces in images into entities

I'm having a lot of difficulty matching an image url with spaces. I need to make this http://site.com/site.com/files/images/img 2 (5).jpg into a div like this: .replace(/(http:\/\/([^\s]+\.(jpg|png|gif)))/ig, "<div style=\"background: url($1)\"></div>") Here's the thread about that: http://stackoverflow.com/questions/1066697/rege...

Count number of matches of a regex in Javascript

I wanted to write a regex to count the number of spaces/tabs/newline in a chunk of text. So I naively wrote the following:- numSpaces : function(text) { return text.match(/\s/).length; } For some unknown reasons it always returns 1. What is the problem with the above statement? I have since solved the problem with the following:- num...

Simple javascript regular expression - add another keyword

How can I update this regular expression to find and replace not just "/news/" but "/blog/" as well? urlLinks = $(this).attr("href").replace(/(\/news\/)/, "$1article/"); It's a simple one. Thanks! ...

How to omit commented lines using RegEx

Hi, can somebody tell me how to avoid commented lines when using a regular expression in Visual Studio? I tried ^[^//]* but it deosn't work. For example, I want to omit following line when I search: //Hello ...

Regex match numeral inside html tags

I need to match the numbers inside a html tag. IE Sometext<sometag><htmltag>123123</htmltag></sometag> I need to create a regex that finds the number that is inside the html tag of my choice, in this case the <htmltag> Thanks everyone :) ...