regex

Ruby Regexp to extract specific elements in an XML string

I have a simple XML string, that is more or less always the same. I'd rather avoid using an XML parser for such a little piece of code, and I though Regexp would help. The XML string looks like : <?xml version="1.0"?> <methodCall> <methodName>weblogUpdates.extendedPing</methodName> <params> <param> <value>Official Google...

Get a 2 String array from HTML .... using regex?

I'm working on a personal project to auto fill out the USPS Click & Ship form and then output the Ref# and the Delivery Confirmation # So far I've been able to get the whole process done, but I can't for the life of me figure out how to pull out the Ref# (which is my order #) and the Delivery Confirmation # Basically for every package ...

Is there any regular expression engine which do Just-In-Time compiling?

My Questions is Is there any regular expression engine which do Just-In-Time compiling during regex pattern parsing and use when matching/replacing the texts? or where can I learn JIT for i386 or x64 architecture? Why I need that is, I recently trying to benchmark python's built-in regex engine with normal C codes with around 10M da...

C# - Removing special character camel style word

I am splitting words from camel style string.Example string str = "winAgainWinBest"; string r = @"(?=[A-Z])"; var splitted = Regex.Split(str, r); I get the result win Again Win Best When the string is mixed with special characters how will i remove it and get the words? I mean string str = "win++Again@@Win--Best\\"; ...

How to remove diacritics from text?

I am making a swedish website, and swedish letters are å, ä, and ö. I need to make a string entered by a user to become url-safe with PHP. Basically, need to convert all characters to underscore, all EXCEPT these: A-Z, a-z, 1-9 and all swedish should be converted like this: 'å' to 'a' and 'ä' to 'a' and 'ö' to 'o' (just remove the...

Regex to Split 1st Colon

I have a time in ISO 8601 ( 2009-11-19T19:55:00 ) which is also paired with a name commence. I'm trying to parse this into two. I'm currently up to here: import re sColon = re.compile('[:]') aString = sColon.split("commence:2009-11-19T19:55:00") Obviously this returns: >>> aString ['commence','2009-11-19T19','55','00'] What I'd li...

Best way to change "bob@???.???" to "[email protected]" using Ruby ?

What's the best way of doing this: mail = "[email protected]" mail2 = mail.do_magic # puts mail2 will return "[email protected]" I'm thinking regex of course, but is there another cool way? If not, how should I do it using regexp? ...

How to get fields from such a string?

I'm importing some data from a database. The data has been stored by a CMS written in php where I have no control. Here is the data (a dense report from a paypal response): a:56:{ s:8:"business";s:19:"[email protected]"; s:14:"receiver_email";s:19:"[email protected]"; s:11:"receiver_id";s:13:"KVBRSDFJKLWYE"; s:9:"item_name";s:4:"ABC...

PHP Multiple digits regular expression

I need to extract the digits from the following string using regular expression: pc 32444 xbox 43567 so my array will be array ([0] => 32444 [1] => 43567) Can someone help construct a preg_match for me? Thanks! ...

Filter a string to contain only alnum chars + a hyphen?

Hello, I would like to filter a string and strip all characters that are not alphanumeric or a hyphen. Is there some tunction in PHP for that? Not sure how to do it. ...

URL Rewriter not grabbing the exact match

I'm implementing some url rewriting using UrlRewriter. So going to http://domainname/11 will go to ~/Items/Details.aspx?Itemid=11 <rewriter> <rewrite url="~/1" to="~/Items/Details.aspx?ItemId=1" /> <rewrite url="~/2" to="~/Items/Details.aspx?ItemId=2" /> <rewrite url="~/3" to="~/Items/Details.aspx?ItemId=3" /> <rewri...

Need help with RegEx for ranges

I want to be able to use a RegEx to parse out ranges like a Windows Print dialog (such as 1-50,100-110,111,112). The following is my current code and I am not clear on how to parse for the additional commas and numbers. I can parse out the hyphen, but not sure how to do it for additional commas or hyphens private void tboxRowNum_Leave(o...

How to Regular Expression match not having a constant at the end of a string (.net validator)

The item referenced in this question does not seem to work for me. I'm using the Regular Expression validator in .net I need to pass validation if the input field does NOT look like this "bagdfsdf -CONST" When I use "(?>!-CONST)$" and ".*(?>!-CONST)$" the regular expression validator never allows it. If I have -CONST at the end or no...

Regular Expression for ASP.NET ID Using Javascript

I am trying to extract the word "need" from this string. ctl00_ctl00_ContentMainContainer_ContentColumn1__needDont_Panel1 I have tried [__]([.]?=Dont) This is using javascript .match() I have even tried to use http://gskinner.com/RegExr/ but just can't solve this one. Thanks for the help! ...

preg_match returning weird results

I am searching a string for urls...and my preg_match is giving me an incorrect amount of matches for my demo string. String: Hey there, come check out my site at www.example.com Function: preg_match("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", $string, $links); echo count($links); The result comes out as 3. Can anybody help...

Get Youtube Video ID from html code with PHP

I want to get all only youtube video ID from html code look the (or multiple) object/embed code for youtube video // html from database <p>loremm ipsum dolor sit amet enot <a href="link" attribute=""blah blah blah">anchor link</a> </p> <object width="425" height="344"> <param name="movie" value="http://www.you...

.net regex group that doesn't appear in matches

is there a way to group a matching element but not have that match appear in the resulting match groups? for example, suppose I have a string with two lines: <td>text 1</td> <td><a href=whatever>this is</a> text 2</td> and I want to parse out "text 1" and "this is text 2". what I'm doing now is using this pattern: <td>(<a href=.+?>)?...

How can I add characters at the beginning and end of every non-empty line in Perl?

I would like to use this: perl -pi -e 's/^(.*)$/\"$1\",/g' /path/to/your/file for adding " at beginning of line and ", at end of each line in text file. The problem is that some lines are just empty lines and I don't want these to be altered. Any ideas how to modify above code or maybe do it completely differently? ...

Why do my captures not work in .NET regex?

I'm parsing some text (admittedly HTML, but it's small stuff, and RegEx (should) do the job fine). I'm trying to use some captures, but they just don't do what I think they should. Match m = new Regex("(.*?)<br>(.*?)/(.*?)/(.*)", RegexOptions.None).Match("word<br>stuff1/stuff2/stuff3") CaptureCollection c = m.Captures; To my mind, c...

How to search/replace text with an "a href" wrapper in JavaScript?

I've converted html to a string, I'm able to use replace in that string to wrap the text with a link, and I can put that html back into the ID it came from. My problem is that my replace method is going inside existing links on the page. This could create nested links, which is a problem. Does anyone out there know how to prevent the re...