regex

mod 11 check digit with regex

Is it possible to create a mod 11 check digit routine with a regex statement? THe nubmer is a 10 digit number, Step 1: A = (2nd number * 2) + (3rd number * 4) + (4th number * 8) + (5th number * 5) + (6th number * 10) + (7th number * 9) + (8th number * 7) + (9th number * 3)) Step 2: B = A / 11 (ignor remainder) Step 3: C = B * 11 S...

Regex that matches anything before a certain character?

I have to parse a bunch of stats from text, and they all are formatted as numbers. For example, this paragraph: A total of 81.8 percent of New York City students in grades 3 to 8 are meeting or exceeding grade-level math standards, compared to 88.9 percent of students in the rest of the State. I want to match just the 81 a...

Replacing a substring using regular expressions

I want to add a call to a onclick event in any href that includes a mailto: tag. For instance, I want to take any instance of: <a href="mailto:[email protected]"> And change it into: <a href="mailto:[email protected]" onclick="return function();"> The problem that I'm having is that the value of the mailto string is not consistent. ...

Regular Expression Help

Hey Guru's, I am looking for some help on creating a regular expression that would work with a unique input in our system. We already have some logic in our keypress event that will only allow digits, and will allow the letter A and the letter M. Now I need to come up with a RegEx that can match the input during the onblur event to ens...

Matcher.appendReplacement with literal text

I am using Matcher.appendReplacement() and it worked great until my replacement string had a $2 in it: Note that backslashes ( \ ) and dollar signs ($) in the replacement string may cause the results to be different than if it were being treated as a literal replacement string. Dollar signs may be treated as references to ...

How can I get an accurate absolute url from get_absolute_url with an included urls.py in Django?

I've building a app right now that I'm trying to keep properly decoupled from the other apps in my Django project (feel free to lecture me on keeping Django apps decoupled, I'd be happy to learn more any/all the time). My problem is this: The get_ absolute_url() method I've written is returning a relative path based on my view. I think ...

how to know whether preg_replace() didn't match or matched from start?

both conditions returns false,how to distinguish them? can it be done without using the third parameter? ...

How can I do a global regular expression match in Perl?

I am trying to come up with a regular expression in Perl matching multiple patterns and returning all of them like preg_match_all in PHP does. Here's what I have: $str = 'testdatastring'; if($str =~ /(test|data|string)/) { print "its found index location: $0 $-[0]-$+[0]\n"; print "its found index location: $1 $-[1]-$+[1...

Regex to detect urls that where the last 'segment' contains a period

I need a regular expression that detects if a given string is a url to a [potential] file ie /file.pdf http://www.whatever.com/file.docx ../file.longfileextension Thanks guys ...

Extract address from description with regex

Im trying to extract an address (written in french) out of a listing using regex. here is the example: "Don't wait, this home won't be on the market for long! Pictures can be forwarded upon request. 123 de la street - city 345-555-1234 " Imagine that whole thing is item.description. Here is a working set so far: In "item.descriptio...

string.Format on my regex is giving me spaces in place of curly braces?

My regex after a String.Format(c#): (^{0})|({0}[-!#$%&'}()+,./:;<=>?@\{{|~"])|([-!#$%&'()*+,./}:;<=>?@_{|~"]{0})|( {0} ) When the regex is coming through the debugger it looks like this: (^ Word )|( Word [-!#$%&'}()+,./:;<=>?@\{|~"])|([-!#$%&'()*+,./}:;<=>?@_{|~"] Word )|( Word ) The curly braces for my string.format have be...

Identifying if a URL is present in a string

Hi can someone help me identify if a url is present in a string using PHP? I want to pull in a full string i.e. "Hi please visit http://domain.com/12345 today" and strip out the full url not just the domain name. Thanks ...

Is there a regular expression to strip specific query variables from a URI?

I have a bunch of HTML that is generated by a daemon using C, XML and XSL. Then I have a PHP script which picks up the HTML markup and displays it on the screen I have a huge swathe of XHTML 1 compliant markup. I need to modify all of the links in the markup to remove &amp;utm_source=report&amp;utm_medium=email&amp;utm_campaign=report. ...

notepad++ regular expression to match files ending with same extention?

Hello, I have many lines like this in a sql file VALUES (12654, 'somestuff', 'some description here', 'filename.swf', '5', 0, 1, '', '500', '300', 'filename.png', '3', '1'); I want somthing to find filename.swf and replace them with folder/filename.swf and then do the same the same for png files I have very basic knowledge,...

Regex group capture in R

In R, is it possible to extract group capture from a regular expression match? As far as I can tell, none of grep, grepl, regexpr, gregexpr, sub, or gsub return the group captures. I need to extract key-value pairs from strings that are encoded thus: \((.*?) :: (0\.[0-9]+)\) I can always just do multiple full-match greps, or do some...

Help on a better way to parses digits from a String in Java

I have a string which contains digits and letters. I wish to split the string into contiguous chunks of digits and contiguous chunks of letters. Consider the String "34A312O5M444123A". I would like to output: ["34", "A", "312", "O", "5", "M", "444123", "A"] I have code which works and looks like: List<String> digitsAsElements(String...

Is there a way to precompile a regex in Perl?

Is there a way to precompile a regex in Perl? I have one that I use many times in a program and it does not change between uses. ...

Regex help, greedy vs. non-greedy

Hey all I have a large html string like <a style="background: rgb(100, 101, 43) none repeat scroll 0% 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-backg round-inline-policy: -moz-initial;" href="#">swatch4</a> <a style="background: rgb(34, 68, 33) none repeat scroll 0% 0%; -moz-background-clip...

How can I strip block comments with Perl?

I am working on a preprocessor that is analyzing a DSL. My goal is to remove the comments. The block comment facility is demarcated by %% before and after. I do not have to worry about %% being in strings, by the definition of the language. I am using this s/// regex. Unfortunately, it seems to match everything and wipe it out: #Remove...

My regex in python isn't recursing properly

I'm suppose to capture everything inside a tag and the next lines after it, but it's suppose to stop the next time it meets a bracket. What am i doing wrong? import re #regex regex = re.compile(r""" ^ # Must start in a newline first \[\b(.*)\b\] # Get what's enclosed in brackets \n...