regex

Regular expression to match a string (1+ characters) that does NOT end in .ext

I need to test a url that it does not end with .asp So test, test.html and test.aspx should match, but test.asp should not match. Normally you'd test if the url does end with .asp and negate the fact that it matched using the NOT operator in code: if(!regex.IsMatch(url)) { // Do something } In that case the regular expression would ...

.NET Regular Expressions in Infinite Cycle

I'm using .NET Regular Expressions to strip HTML code. Using something like: <title>(?<Title>[\w\W]+?)</title>[\w\W]+?<div class="article">(?<Text>[\w\W]+?)</div> This works for 99% of the time, but sometimes, when parsing... Regex.IsMatch(HTML, Pattern) The parser just blocks and it will continue on this line of code for several ...

xsd pattern restriction - disallow backslash

I have a requirement to disallow backslash characters in a given string field defined by an xsd document. However, being as green as I am, I am not confident with my xsd and/or regex knowledge. Here is what I have so far: <xs:simpleType name="BackslashRestrictedField"> <xs:restriction base="xs:string"> <xs:minLength value="0" />...

Regex to match for zeros

Hi, I am looking for a regex pattern that would match several different combinations of zeros such as 00-00-0000 or 0 or 0.0 or 00000 Please help Thanks! EDIT: Well, I have web service that returns me a result set, based on what it returns me I can decide if the result is worth displaying on the page. So if I get either 00-00-0000 ...

Trying to use Visual studio IDE (Find & Replace) as a quick & dirty regex tool but stucked

I have a xml text file opened in VS2005 IDE. It has 4 mocked up lines: <mc id="dog" name="mydogBob"/> <mc id="cat" name="katie"/> <mc id="turtle" name="slow"/> <mc id="fish" name="happy"/> How do I use VS2005 Find/Replace function with regular expression to replace words and make the final result like: dog cat turtle fish Thank yo...

How to convert imperial units of length into metric?

Here I am faced with an issue that I believe(or at least hope) was solved 1 million times already. What I got as the input is a string that represents a length of an object in imperial units. It can go like this: $length = "3' 2 1/2\""; or like this: $length = "1/2\""; or in fact in any other way we normally would write it. In ef...

Best way to parse a dynamic text list in PHP.

I have below a list of text, it is from a popular online game called EVE Online and this basically gets mailed to you when you kill a person in-game. I'm building a tool to parse these using PHP to extract all relevant information. I will need all pieces of information shown and i'm writting classes to nicely break it into relevant encap...

RegExp match one Word or Multiple Words in Quotes

I need a RegExp which matches a word or multiple words in quotes. [\w]* matches a word "[\w\W&&[^"]]*" matches multiple words in quotes. (btw, not sure why \w\W works, but not a simple . (which should match all characters) So how do i combine these two regexp? ...

Basic vb.net RegEx Matches question

I need to loop through all the matches in say the following string: <a href='/Product/Show/{ProductRowID}'>{ProductName}</a> I am looking to capture the values in the {} including them, so I want {ProductRowID} and {ProductName} Here is my code so far: Dim r As Regex = New Regex("{\w*}", RegexOptions.IgnoreCase) Dim m As Match = r.Ma...

Why is this regex returning errors when I use it to fish img src's from HTML?

I'm writing a function that fishes out the src from the first image tag it finds in an html file. Following the instructions in this thread on here, I got something that seemed to be working: preg_match_all('#<img[^>]*>#i', $content, $match); foreach ($match as $value) { $img = $value[0]; } $stuff = s...

XML parsing and transformation in PHP?

I have a custom XML schema defined for page display that puts elements on the page by evaluating XML elements on the page. This is currently implemented using the preg regex functions, primarily the excellent preg_replace_callback function, eg: ... $s = preg_replace_callback("!<field>(.*?)</field>!", replace_field, $s); ... function r...

Scrape a price off a website

Hi, I'm trying to scrape a price from a web page using PHP and Regexes. The price will be in the format £123.12 or $123.12 (i.e., pounds or dollars). I'm loading up the contents using libcurl. The output of which is then going into preg_match_all. So it looks a bit like this: $contents = curl_exec($curl); preg_match_all('/(?:\$|£)[0-...

Regex to replace all \n in a String, but no those inside [code] [/code] tag

Hi, I need help to replace all \n (new line) caracters for in a String, but not those \n inside [code][/code] tags. My brain is burning, I can't solve this by my own :( Example: test test test test test test test test [code]some test code [/code] more text Should be: test test test<br /> test test test<br /> test<br /> test<br /...

How can I make this Perl one-liner to toggle character in line in a file?

I am attempting to write a one-line Perl script that will toggle a line in a configuration file from "commented" to not and back. I have the following so far: perl -pi -e 's/^(#?)(\tDefaultServerLayout)/ ... /e' xorg.conf I am trying to figure out what code to put in the replacement (...) section. I would like the replacement to inser...

Need a regex to add css class to first and last list item

UPDATE: Thank you all for your input. Some additional information. It's really just a small chunk of markup (20 lines) I'm working with and had aimed to to leverage a regex to do the work. I also do have the ability to hack up the script (an ecommerce one) to insert the classes as the navigation is built. I wanted to limit the number ...

There is a function to use pattern matching (using regular expressions) in C++?

There is a simple C++ method to use pattern matching on strings? The code should sound like this: if (regexpcmp("l?nole*[0-9]", "linoleum1")) { //we have a match! } else { //no match } ...

Parsing a string for nested patterns

What would be the best way to do this. The input string is <133_3><135_3><116_2>The other system worked for about 1 month</116_2> got some good images <137_3>on it then it started doing the same thing as the first one</137_3> so then I quit using either camera now they are just sitting and collecting dust.</135_3></133_3> the expect...

Common Regular Expressions

Is there a site online that lists common regular expressions or has a utility to help you create one based on sample text? Thanks! ...

Need help refining this javascript regex

I have the following very simple Javascript-compatible regular expression: <script type="text/javascript" id="(.+)" src="([^"]+)"> I am trying to match on script tags and gather both the ID and src attributes. I'd like to make the order of the attributes irrelevant, so that the following will still match: <script id="..." type="text/...

What is the best way to catch and show an error if user enters only whitespace in a form field in Django?

In Django 1.0, what is the best way to catch and show an error if user enters only whitespace (" ") in a form field? class Item(models.Model): description = models.CharField(max_length=100) class ItemForm(ModelForm): class Meta: model = Item if user enters only whitespace (" ") in description CharField, what change ne...