regex

Regular expression (/<(\w+)\s+(.*?)>/) need improvement

Hi, There is a sub to handle the Type and Value. sub parse_type_value_specifier { my $tvs = shift; my ($type, $value) = $tvs =~ /<(\w+)\s+(.*?)>/; return $type, $value; } It should suit for three formats below. <B 0> - works, return $type = (B) and $value = (0) <A[1..80] ""> - doesn't work, need return $type = A[1..80]...

Javascript function to validate time 00:00 with regular expression.

I am trying to create a javascript function with regular expression to validate and format the time 24 hours, accepting times without semicolon and removing spaces. Examples: If the user types "0100", " 100" or "100 " it would be accepted but formatted to "01:00" If the user types "01:00" it would be accepted, with no need to format. Th...

Matching words in UTF-8 encoded string with Ruby 1.9.1

I want to match all individual words in given string, provided that String is UTF-8 encoded, and then I spellcheck each word. Everything works with my code provided it's english-only text, but if there are some, say, German characters, my words are split in two on these characters. How can I match single words from text, that contain lat...

How to write a Multi-line RegEx Expression

I have a vb.net class that cleans some html before emailing the results. Here is a sample of some html I need to remove: <div class="RemoveThis"> Blah blah blah<br /> Blah blah blah<br /> Blah blah blah<br /> <br /> </div> I am already using RegEx to do most of my work now. What would the RegEx exp...

Standard Regex vs python regex discrepancy

I am reading a book and they provide an example of how to match a given string with regular expressions. Here is their example: b*(abb*)*(a|∊) - Strings of a's and b's with no consecutive a's. Now I've tried converting it to python like so: >> p = re.compile(r'b*(abb*)*(a|)') # OR >> p = re.compile(r'b*(abb*)*(a|\b)') # BUT it still...

PHP search a string for a email address

Hi Im attempting to search a string to see whether it contains a email address - and then return it. A typical email vaildator expression is: eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); However how would I search if that is in a string, for example return the email address in the string: "...

"Optional" backreferences in regular expression

I'm not sure if my subject is correct but here is what I'm wanting to accomplish. I have a regular expression with two groups that are OR'd and I'm wondering if it's possible to have a group be a back reference only if it matched? In all cases, I'm wanting to match spam.eggs.com Example: import re monitorName = re.compile(r"HQ01 : HTT...

replacing html link with regex and yahoo pipes

my question is similar to the one here: http://stackoverflow.com/questions/360492/regular-expression-on-yahoo-pipes i have my gmail status hooked up to twitter through friendfeed, but unfortunately, they truncate the link text, and my links aren't working once they get to twitter. I need to be able to take this: <div style="margin-to...

Is there any way to have dot (.) match newline in C++ TR1 Regular Expressions?

I couldn't find anything regarding this on http://msdn.microsoft.com/en-us/library/bb982727.aspx. Maybe I could use '[^]+' to match everything but that seems like a hack? Thanks. ...

Validating HTML text box with javascript and regex

The below code works to only allow alphanumerics and spaces. However, I would like to also allow an accented character (Ã). How should the regex be modified? Thanks <html> <head> <script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; <script type="text/JavaScript"> $(fun...

Regular expression to search for a specific string along with unknowns

Hey! Im attepting to find the regex to pull the http://{any_string}.blogspot.com/feeds/{any_string}/comments/default out of <link rel="alternate" type="application/atom+xml" title="{any_string}" href="http://{any_string}.blogspot.com/feeds/{any_string}/comments/default" /> I know basics of regex and using eregi but im unsure...

How to check that vsprintf has the correct number of arguments before running.

I'm trying to use vsprintf() to output a formatted string, but I need to validate that I have the correct number of arguments before running it to prevent "Too few arguments" errors. In essence I think what I need is a regex to count the number of type specifiers, but I'm pretty useless when it comes to regex and I couldn't fund it anyw...

Helped needed on RegEx

I am still learning RegEx so I need some help on this one. Rules are as below: Min/Max Length of string: 1-5 String has to be a whole word String can contain: A-Z and/or a-z and/or 0-9 or combination of both only (e.g. _ - . * are not allowed) Examples: 12345 – allowed Os342 – allowed 2O3d3 – allowed 3sdfds dsfsdf – not allowed Sdf...

PHP - Remove last character if it's a period?

How to remove the last character only if it's a period? $string = "something here."; $output = 'something here'; ...

fastest way to compare strings in python

I'm writing a script in Python that will allow the user to input a string, which will be a command that instructs the script to perform a specific action. For the sake of argument, I'll say my command list is: lock read write request log Now, I want the user to be able to enter the word "log" and it will peform a specific action, whi...

get city, state or zip from a string in python

I'd like to be able to parse out the city, state or zip from a string in python. So, if I entered Boulder, Co 80303 Boulder, Colorado Boulder, Co 80303 ... any variation of these it would return the city, state or zip. This is all going to be user inputted data and inputted in one text field. ...

How would I validate string length using DataAnnotations in asp.net mvc?

I am using DataAnnotations in an ASP.NET MVC 1 application to check for Required fields and numerical ranges using the Required and Range attributes. I am looking for the best way to validate the length of strings in a few input text boxes. I see that there is a RegularExpression attribute that could do the job but I was wondering if ...

How to match the coupled string with regular expression?

I want to match this kind of format: AA sysodufsoufdds AA Where AA can be arbitary consecutive string with no space in it. Is there a solution? ...

Regex to replace integer between two pound / hash symbols in php

Looking to replace: #678# with <span id="note-678"></span> ...

Recursive regular expression,how to match the coupled string with regular expression?

... AA BB sysodufsoufdds BB AA ... Where AA,BB can be arbitary consecutive string with no space in it. But I want to get the outest pair:AA More examples: Input: a HH CC abc CC HH c Output: HH Input: x YYYY j DD GG DD hsu DD GG DD k YYYY o Output: YYYY To make my question more general,how to match a speci...