regex

Regex Match PHP Comment

Ive been trying to match PHP comments using regex. //([^<]+)\r\n Thats what ive got but it doesn't really work. Ive also tried //([^<]+)\r //([^<]+)\n //([^<]+) ...to no avail ...

Using regular expressions to get a word in between two Key words

It has been a while since I have used regular expressions and I'm hoping what I'm trying to do is possible. I have a program that sends automated response regarding a particular file and I'd like to grab the text between two words I know will never change. In this example those words are "regarding" and "sent" Dim subject As String = "...

How do you match 12 hour time hh:mm in a regex?

How could you match 12 hour time in a regex-- in other words match 12:30 but not 14:74? Thanks! ...

tree command as a regex, but without the hidden files

Thanks to a nice post at http://murphymac.com/tree-command-for-mac/, I have my long lost linux command tree so I can see the complete directory tree with a single command. I've implemented it via a function in my .bash_profile like this... function tree { find ${1:-.} -print | set -e "s;[^/]*/; ;g" } ...but what I would like is a v...

How to RegEx Replace named groups

I need to use RegEx.Replace to replace only certain named groups in my input string. So I might have a pattern like: "^(?<NoReplace>.+)(?<FirstPeriod>(\d{2})|CM|RM|PM|CN|RN){1}(?<LastPeriod>(\d{2})|CM|RM|PM|CN|RN){1}((#(?<NumberFormat>[#,\.\+\-%0]+))*)$" Tokens such as CM, RM are being replaced using Regex.Replace with a MatchEvaluat...

Regex to match values not surrounded by another char?

This is one of the toughest things I have ever tried to do. Over the years I have searched but I just can't find a way to do this - match a string not surrounded by a given char like quotes or greater/less than symbols. A regex like this could match URL's not in HTML links, SQL table.column values not in quotes, and lots of other things...

Regex to identify DOS environment variables within braces

The following DOS script snippet has a bug: if not exist %MyFolder% ( mkdir %MyFolder% if %errorlevel% GEQ 1 ( rem WARNING: the line above has a bug! rem %errorlevel% will be the errorlevel rem of the if statement because of the (parentheses) echo Error: Could not create folder %MyFolder% ...

How to wrap text in a hyperlink ONLY if it isn't already wrapped in a hyperlink

I need to do a regex replacement where I take a string and wrap a hyperlink around it (but here's the catch) as long as it isn't already surrounded by a hyperlink. How would I do this? So, for example, let's take the text: The quick brown fox. I want to make "quick brown" a link, like this: The <a href="http://www.stackoverflow.co...

Regex lookahead within option group

I'm matching urls, so I can connect requests to controllers/views, and there are multiple options for a few of the urls, only one of which can have anything following it in the url, but I also need to have what comes after available as a named group. Examples: /admin/something #match /admin/something/new #match /admin/something/new/...

regex to fetch string between [a] and [/a] excluding any other tag like [b][/b] that comes in between

I have an input like the following [a href=http://twitter.com/suddentwilight][font][b][i]@suddentwilight[/font][/a] My POV: Rakhi Sawant hits below the belt &amp; does anything for attention... [a href=http://twitter.com/mallikaLA][b]http://www.test.com[/b][/a] has maintained the grace/decency :) Now I need to get the string @suddentw...

Can someone explain this Python re.sub() unexpected output?

I am using Python 2.6 and am getting [what I think is] unexpected output from re.sub() >>> re.sub('[aeiou]', '-', 'the cat sat on the mat') 'th- c-t s-t -n th- m-t' >>> re.sub('[aeiou]', '-', 'the cat sat on the mat', re.IGNORECASE) 'th- c-t sat on the mat' If this output is what is expected, what is the logic behind it? ...

Javascript Regex: how to replace just the class of attribute for any tr ?

I have the following HTML code: <tr id="1774" class="XXX"><td> <span class="YYY"> Element 1</span></td></tr> <tr id="1778" class="XYZ"><td> <span class="ZZZ">Element 2 </span></td> </tr> I want to replace all the class attributes (just for <tr> s) but not for <td> s. (that would be XXX and XYZ). The replacement would be: *XXX_suffi...

How can I check whether a byte array contains a unicode string in Java

Given a byte array that is either a UTF-8 encoded string or arbitrary binary data, what approaches can be used in Java to determine which it is? The array may be generated by code similar to: byte[] utf8 = "Hello World".getBytes("UTF-8"); Alternatively it may have been generated by code similar to: byte[] messageContent = new byte[2...

regular expression for type specifier in php

I need a regular expression which extract type specifier ( like %d,%s) from a string. <? $price = 999.88; $str = "string"; $string = "this is a %f sample %'-20s,<br> this string is mixed with type specifier like (number:%d's)"; //output 1 :echo sprintf($string,$price,$str,500); //output 2 should b...

Regex for parsing Wikicode in C#

Hi folks, I try to parse articles from wikipedia. I use the *page-articles.xml file, where they backup all their articles in a wikicode-format. To strip the format and get the raw text, I try to use Regular Expressions, but I am not very used to it. I use C# as programming language. I tried a bit around with Expresso, a designer for Reg...

regEx to transform tsql Insert on Update command

I'm not very skilled with regex, I was wondering if it was possible to use a regular expression to transform a string like insert into tblTest (id,title,col1,col2) values (1,'test','test1','test2') into update tblTest set title='test',col1='test1',col2='test2' where id=1 btw, the insert query will not be always like the one I've wr...

regular expression for find [# # 1] , [# # 2] ,[# # 125] .. in php

regular expression for find [# # 1] , [# # 2] ,[# # 125] .. in php i have string "php, regu[]lar expre[# # 1]ssio [# # 2]nssadas das dasd as das dasdssd [# # 301]dfs dfsdf sd fsdfds" want to replace all these with {number} ...

VB.NET Regex.replace <>

Hi Im pretty new to regex and im having trouble using VB and regex. Im trying to remove a <span ....> comment and replace it with <b> so far ive got this: Regex.Replace(text, "<span[^>]*>", "<b>", RegexOptions.IgnoreCase) This correctly matches the span comment but when it replaces it with the string it strips the <> and just leav...

Regex to identify whether a URL is an image or not?

I am getting URLs like this: http://img23.example.com/images/j43j32k3.jpg And I need to identify whether it both: a) Begins with HTTP b) Ends with JPEG, JPG, GIF or PNG I am using Ruby to do the matching I just don't know the Regex for this one.. ...

What is this RegEx statement doing?

I don't claim to be a RegEx guru at all, and I am a bit confused on what this statement is doing. I am trying to refactor and this is being called on a key press and eating a lot of CPU. Regex.Replace(_textBox.Text, "(?<!\r)\n", Environment.NewLine); Thanks. ...