regex

What is the fastest way in C# to find a pattern in a group of files?

using System; using System.IO; using System.Reflection; using System.Text.RegularExpressions; namespace regex { class MainClass { public static void Main(string[] args) { Regex exp = new Regex(@"e(-)?m[a@]il(s)?|input|output|padr(ão|ões)|máquina(s)?|reconhecimento", RegexOptions.IgnoreCase |...

How can I use gvim to add a carriage return (aka ENTER) to a pattern?

What's the vi/gvim syntax to replace a pattern with a pattern that includes <ENTER>? I know this is possible but never felt like diving too deep in the documentation to know how to do it. Something like this: :s/\(word\)/\1<ENTER>/ But correctly :) Thanks ...

How do I use Javascript to modify the content of a node?

I need to use Javascript to do three things: Select all nodes with a class of "foo". Find all words inside these nodes that begin with "*". Surround those words with <span class="xyz"> ... </span>, where xyz is the word itself. For example, the content: <ul> <li class="foo"> *abc def *ghi </li> <li class="bar"> abc *de...

Why does my non-greedy Perl regex match nothing?

Hi, I thought I understood Perl RE to a reasonable extent, but this is puzzling me: #!/usr/bin/perl use strict; use warnings; my $test = "'some random string'"; if($test =~ /\'?(.*?)\'?/) { print "Captured $1\n"; print "Matched $&"; } else { print "What?!!"; } prints Captured Matched ' It seems it has ...

Replacing numbers in strings with C#

I'd thought i do a regex replace Regex r = new Regex("[0-9]"); return r.Replace(sz, "#"); on a file named aa514a3a.4s5 . It works exactly as i expect. It replaces all the numbers including the numbers in the ext. How do i make it NOT replace the numbers in the ext. I tried numerous regex strings but i am beginning to think that its...

Does .NET regular expressions engine support inline mode modifiers?

A C# application my company uses is taking regular expression strings from a database table and matching them on different text files. The problem is that the application has no RegexOptions set as default and I need to use the "Dot matches new line" mode. Does the engine support inline mode modifiers just as like "A(?s)(.*?)(?-s)B" ...

Regex to find a number in a string

I've got a string that may or may not contain a number of 4 or 5 digits. I'm looking for a regex that can detect if the string does in fact have such a number. ...

How to match "Parameter Name: Value" in C# Regex?

I would like to match these lines: ParameterINeed: 758 ParameterCount: 8695 ParameterText: 56 And I would receive a parameter name and parameter value. Could you please tell me how to write Regex.Matches patter for this and how to process this data into Dictionary? I use this code: string Text = "ParameterINeed: 758\r\nParameterCoun...

What is the best way to screen scrape poorly formed XHTML pages for a java app

I want to be able to grab content from web pages, especially the tags and the content within them. I have tried XQuery and XPath but they don't seem to work for malformed XHTML and REGEX is just a pain. Is there a better solution. Ideally I would like to be able to ask for all the links and get back an array of URLs, or ask for the text...

best way to turn a post title into an URL in c#

hi everybody. I was wondering which is the best way to turn a string (e.g. a post title) into a descriptive URL. the simplest way that comes to mind is by using a regex, such in: public static Regex regex = new Regex( "\\W+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace...

How can I remove all tokens with non-word characters in Perl?

I am trying to come up with a regex for removing all words that contain non-word characters. So if it contains a colon, comma, number, bracket etc then remove it from the line, not just the character but the word. I have this so far. $wordline = s/\s.*\W.*?\s//g; Does not have to be perfect so removing strings with dash and apostroph...

mod_rewrite number of parameters/back-references limitation

Apparently there is a limitation (9) on how many backreferences you can access in htaccess RewriteRules.. But we have a RewriteRule that requires more than 9 parameters, something like this: RewriteRule ^([^/]+)/b([0-9]+)(/a([0-9]+))?(/v([0-9]+))?(,([0-9]+))?(/(ajax|share))?(,complete)?$ /index.php?control=sites&site=brands&control_fil...

Split String into Parts PHP

Have the following string i need to split. $string = "This is string sample - $2565"; $split_point = " - "; One: I need to be able to split the string into two parts using a regex or any other match and specify where is going to split. Second: Also want to do a preg_match for $ and then only grab number on the right of $. Any sugges...

Applying a regular expression to a Java I/O Stream

I seek an example of applying a regular expression to a Java I/O stream that doesn't simply convert the stream to a string as I would like to preserve binary data. Most of the examples on the Internet focus on text data... ...

Extract everything between <object></object>

I am using CURL to download a page. Now I want to extract this from the page: <object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="640" height="303.33333333333" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab" id="object701207571"> <param name="autoPlay" value="false" /> <param na...

Regular expression that doesn't contain certain string

I have something like this aabbabcaabda for selecting minimal group wrapped by a I have this /a([^a]*)a/ which works just fine But i have problem with groups wrapped by aa, where I'd need something like /aa([^aa]*)aa/ which doesn't work, and I can't use the first one like /aa([^a]*)aa/, because it would end on first occurence of ...

How to apply <p></p> tags to a text field

Hi all, I've got a varchar() field in SQL Server that has some carriage return/linefeeds between paragraph marks. I'd like to turn it into properly formatted HTML. For instance: ---------- before ---------- The quick brown fox jumped over the lazy dog. Then he got bored and went to bed. After that, he played with his friends. ...

Regular Expression for extracting POP3 headers

Hi, I'm trying to work out how to extract POP3 headers using this regex ^(?[a-zA-Z-]+)(?(?=:).+)$ Delivered-To: [email protected] The group returns the ':' character as well which I want to avoid. I'm busting trying to work this out but can't. Need collective wisdom :-) ...

Simple regular expression help

I need 2 simple reg exps that will: Match if a string is contained within square brackets ([] e.g [word]) Match if string is contained within double quotes ("" e.g "word") Thanks in advance. ...

ASP.net REGEX Question: Find specific match, then skip everything to end tag

strRegex = New StringBuilder strRegex.Append("<td class=""[\s\w\W]*?"">(?<strTKOWins>[^<]+)[\s]*?<span class='[\s\w\W]*?'>(T)KOs[\s\w\W]*?</span>[\s\S]*</td>") Regex = New System.Text.RegularExpressions.Regex(strRegex.ToString, RegexOptions.None) Matches = Regex.Match(results, strRegex....