regex

How must I declare the regex for Perl's split?

I came across this Perl construct today: @foo = split("\n", $bar); That works well for splitting a large string into an array of lines for UNIX-type line endings, but leaves a trailing \r for Windows. So I changed it to: @foo = split("\r?\n", $bar); Which splits the string by lines and doesn't leave a trailing \r (tested under Acti...

preg_split() and converting all links in a string to anchors?

Hey all, I have a string ($string for this example) and I want to do the following: Parse the string and convert all links within it to "actual links" (adding the open/close anchor tag) -- what is the best way to do this? I tried using preg_split() to create an array of the links contained in the string, with the idea of using str_repl...

regex '|' operator vs separate runs for each sub-expression

I've got a fairly large string (~700k) against which I need to run 10 regexes and count all the matches of any of the regexes. My quick and dirty impl was to do something like re.search('(expr1)|(expr2)|...'), but I was wondering if we'd see any performance gains by matching in a loop instead: In other words, I want to compare the perf...

regex tutorial, How can I improve this

I needed a utililty function earlier today to strip some data out of a file and wrote an appaling regular expresion to do it. The input was a file with lots of line with the format: <address> <11 * ascii character value> <11 characters> 00C4F244 75 6C 74 73 3E 3C 43 75 72 72 65 ults><Curre I wanted to strip out everything bar t...

Using C# and regex to parse source code and find function calls with arguments

I have a list of function calls stored in a database, and for some function calls, I care about what the arguments of the function call are. I am parsing C source code with my program (which is in C#). I'm trying to find the best way of getting the function calls with the arguments. I read the source code into a string prior to parsin...

Not that lazy Regex match?

I have a C# Regex class matching multiple subgroups such as (?<g1>abc)|(?<g2>def)|(?<g3>ghi) but with much more complicated sub-patterns. I basically want to match anything that doesn't belong to any of those groups, in addition to existing groups. I tried (?<g1>abc)|(?<g2>def)|(?<g3>ghi)|(.+?) but it turned out too slow. I can'...

I need a php regular expression that replaces one tag with another

Here is what I need to be able to do: I need to match the following tag: <SPAN style="TEXT-DECORATION: underline">text sample</SPAN> I need to replace the span with an html3 compliant tag, but keep the text in between. The final tag should look like this after replacement: <u>text sample</u> I'm just not good with regular express...

Regex Basics: grab text between two constants

Stuck on a (rather simple) regex problem in PHP. Buried in a mess of text is this section: &lt;tr&gt; &lt;td id=&quot;descriptionArea&quot;&gt; Customer request to remove &quot;Intro - 01/13/09&quot; video clip. &lt;br/&gt; &lt;/td&gt; &lt;/tr&gt; I want whatever is between: description...

How to search for all methods in a project that return implementation of Collection interface?

I've been reading Josh Bloch's 'Effective Java 2nd Edition'. Item 43 states 'Return empty arrays or collections, not nulls'. My question is how can I search for all methods in a project that return an implementation of java.util.Collection interface? IDE that is used is Eclipse, but any way of finding the right result is acceptable, e.g....

Regex for variable declaration and initialization in c#

I want to write a RegEx to pull out all the variable values and their names from the variable declaration statement. Say i have int i,k = 10,l=0 i want to write a regex something like int\s^,?|(^,?)* but this will also accept k = 10 i.e. (without int preceding it) Basically idea is If string starts with int then get the variable list s...

Regular expression (glob) search tree

Anyone know how one might adapt a search tree to handle limited regular expressions? The task is, given a file name, find all nodes matching that file name. Nodes may contain usual file name globs (* and ?). Obviously, since this is a search tree, speed is of the essence. EDIT: I should add that the most important case for speed is the ...

Python regular expression matching a multiline block of text

I'm having a bit of trouble getting a Python regex to work when matching against text that spans multiple lines. The example text is ('\n' is a newline) some Varying TEXT\n \n DSJFKDAFJKDAFJDSAKFJADSFLKDLAFKDSAF\n [more of the above, ending with a newline]\n [yep, there is a variable number of lines here]\n \n (repeat the above a few hu...

How can I expand variables in a Perl string?

I am trying to expand the string $searchCriteria in the if condition. Any clues? use strict; my $argNum; my $searchCriteria = ""; foreach $argNum (0 .. $#ARGV) { $searchCriteria = $searchCriteria . "(\$_ =~ \/" . $ARGV[$argNum] . "\/i) && "; } $searchCriteria =~ s/&& $//; #print $searchCriteria; open IP, "<vm.txt" or die $!; my ...

Extending [^,]+, Regular Expression in C#

Duplicate http://stackoverflow.com/questions/585853/regex-for-variable-declaration-and-initialization-in-c I was looking for a Regular Expression to parse CSV values, and I came across this Regular Expression [^,]+ Which does my work by splitting the words on every occurance of a ",". What i want to know is say I have the string...

Match at every second occurence

Is there a way to specify a regular expression to find every 2nd occurrence of a pattern in a string? Examples searching for a against string abcdabcd should find one occurence at position 5 searching for ab against string abcdabcd should find one occurence at position 5 searching for dab against string abcdabcd should find no occur...

Getting Matched Values in the Same Group, RegEx C#

Hi friends, I have a string: type_name "abc" < text1 > text2 > > "ab123" < text3 Now I want to extract all alphanumeric words which are preceded by a "<" or ">" So I wrote: [<>]\s*(?'name'\w+) I'm getting the matches, (and for example above I get 3 matches, each has a group called name) and in name I'm able to access the val...

How to find a relative URL and translate it to an absolute URL in Python

I extract some code from a web page (http://www.opensolaris.org/os/community/on/flag-days/all/) like follows, <tr class="build"> <th colspan="0">Build 110</th> </tr> <tr class="arccase project flagday"> <td>Feb-25</td> <td></td> <td></td> <td></td> <td> <a href="../pages/2009022501/">Flag Day and Heads Up: Power Aware Di...

Regex on an array?

Hi How do I get the percentage and filesize from this sort of string using regex in PHP? The thing is I get this string using the print_r function like so: while(!feof($handle)) { $progress = fread($handle, 8192); print_r($progress); } The above outputs something like this: [download] 28.8% of 1.51M at 171.30k/s ETA 00...

I don’t get regular expressions

I don’t understand or see the need for regular expressions. Can some explain them in simple terms and provide some basic examples where they could be useful, or even critical. ...

c# Regex problem

hi ,i want search a value in on row like this <p align="center"><input type="hidden" name="e79e7ec" value="15302f565b"> i need name="" value and value="" value :P create this code , but this code dosent work Regex rloginRand = new Regex(@"<p align=center><input type=hidden name=\w*"); Match mloginRand = rloginRand.Match...