regex

Build regex to find and replace invalid HTML attributes

Hello, The sad truth about this post is that I have poor regex skills. I recently came across some code in an old project that I seriously want to do something about. Here it is: strDocument = strDocument.Replace("font size=""1""", "font size=0.2") strDocument = strDocument.Replace("font size='1'", "font size=0.2") strDocument = strD...

Replacing a string of text with another string using preg_replace

I have a string Action - [N]ew, [U]pdate, or [D]elete : N that I need to replace with "Action - [N]ew, [U]pdate, or [D]elete : U" somhow by using preg_replace I can't get it working. It remains the same. My code looks like this $action = Action - '[N]ew, [U]pdate, or [D]elete : U'; $line = preg_replace("/(Action - [N]ew, [U]pdate, or [...

regexp to match string1 unless preceded by string2

Using Ruby, how can I use a single regex to match all occurrences of 'y' in "xy y ay xy +y" that are NOT preceded by x (y, ay, +y)? /[^x]y/ matches the preceding character too, so I need an alternative... ...

Use a String as an E4X Expression in AS3?

I need to use a string to access nodes and attributes in XML using E4X. It would be ideal to have this scenario (with XML already loaded): var myXML:XML = e.target.data; var myStr:String = "appContent.bodyText.(@name == 'My Text')"; myXML.myStr = "New Value for bodyText node where attribute('name') is equal to 'My Text'"; I ultimate...

Long Regex - How would you do it?

Hey guys, I have a regular expression that is pretty long, and is hard to look at. i was wondering if you could help shorten it up, so it's more manageable. I admit, I'm not a regexp guru, and I just hack away to get by. If you come up with something better (it doesn't even have to be shorter), please explain your reasoning, so I might h...

How are regular expressions processed?

How are regular expressions processed? ...

Break a CSS file into an array with PHP

I wanted to break a css file into an array with PHP. Ex: #selector{ display:block; width:100px; } #selector a{ float:left; text-decoration:none; } Into a php array... array(2) { ["#selector"] => array(2) { [0] => array(1) { ["display"] => string(5) "block" } [1] => array(1) { ["width"] => string(5) "100px" ...

Javascript String.replace with dynamic regular expressions?

I have the following code, which works, but I need to inject some different stuff into the regular expression object (regex2) at runtime. However, text.replace does not seem to like a string object for the regular expression, so how can I make this work? var regex2 = /\|\d+:\d+/; document.write("result = " + text.replace(regex2, '') + "...

Regex comparison

I'm (finally) starting to learn regex, and I'm wondering if there's any notable difference between these two pattern strings. I'm trying to match lines such as "Title=Blah", and match "Title" and "Blah" in two groups. The problem comes with titles like "Title=The = operator". Here are the two choices to solve the problem: ^([^=]+)=(.+)...

Surrounding all instances of @________, #___________, and http://_________ with anchor tags?

Related (but slightly different): http://stackoverflow.com/questions/1181204/javascript-regex-surround-and-http-with-anchor-tags-in I would like to surround all instances of @___, #____, and http://________ with anchor tags. Multiple passes is fine with me. For example, consider this Twitter message: The quick brown fox @Spreadt...

Dynamic Regex in Ruby

I am trying to find a way to let me dynamically create a regexp object from a string (taken from the database) and then use that to filter another string. This example is to extract data from a git commit message, but in theory any valid regexp could be present in the database as a string. What happens >> string = "[ALERT] Project: Rev...

Using Intelligencia UrlRewriter regex .asp pages to a holding page

When looking over the statistics for my site, I realized that the vast majority of traffic is coming via third party links to classic ASP pages which haven't existing for a few years now. I decided that adding a bunch of urlMappings to the web.config wasn't a great idea, so I added Intelligencia UrlRewrite and tried to add a rule, as fo...

Help with Regex - Wordpress (search-regex)

My first attempt using RE has me stuck. I'm using Regex on a Wordpress website via the Search-Regex Plugin and need to match on a specific " buried within a bunch of html code. HTML example: provide brand-strengthening efforts for the 10-school conference.&#0160; </p> <p> <a href="http://www.learfield.com/oldblog/.a/6a00d8345233fa6...

How to extract value betwen two string using regex?

Here is the demo String: beforeValueAfter Assume that I know the value I want is between "before" and "After" I want to extact the "Value" using the regex.... pervious909078375639355544after Assume that I know the value I want is between "pervious90907" and "55544after" I want to extact the "83756393" using the regex.... thx...

Help with regex

I'm looking for a regex that will recognize # followed by a number in a string and make it clickable. Only if its # and a number like ex: #758 and make i clickable. Not # 758. Youtube has this for example. Would really appreciate if someone could give me some hints since im worthless on regex. ...

replace cell values within excel using excel.interop

I want to scan an excel sheet, and replace any occurrences of social security numbers with zeros... I would like to do this using Excel.Interop if at all possible, but I'm open to anything at this point... here's some of my code... I'm banging my head on the desk for the past few months... // Get range and convert it to a string varia...

DFA based regular expression matching - how to get all matches!

Hi! I have a given DFA that represent a regular expression. I want to match the DFA against an input stream and get all possible matches back, not only the lestmost-longest match. For example: regex: a*ba|baa input: aaaaabaaababbabbbaa result: aaaaaba aaba ba baa Sorry for my English! Thanks for your help! ...

I have HTML comments being wrapped in Li and P tags :(

I have content that is first htmlentities and then stripslashes followed by nl2br. This means a watermark at the end ends up as: <li><p><!-- watermark --></p></li> Not very useful. I have the code below to try and strip the html comments and stop it displaying but its not very good at it! $methodfinal = str_replace('<li><p><!--', '<...

How do I convert a regular expression in a valid .NET format to valid Java format?

Hi, I want to use the following regular expression which is written within a C# .NET code, in a Java code, but I can't seem to convert it right, can you help me out? Regex(@"\w+:\/\/(?<Domain>[\x21-\x22\x24-\x2E\x30-\x3A\x40-\x5A\x5F\x61-\x7A]+)(?<Relative>/?\S*)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singlelin...

Regex - A expert should solve this in seconds

Hi There I were wondering if anyone can help me with a regex I want to insert the following into a database: (#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#), (#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #text9#), (#text1#,#text2#,#text3#,#text4#,#text5#,#text6#, #text7#, #text8#, #te...