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...
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...
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...
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...
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...
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'...
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...
Stuck on a (rather simple) regex problem in PHP.
Buried in a mess of text is this section:
<tr>
<td id="descriptionArea">
Customer request to remove "Intro - 01/13/09" video clip.
<br/>
</td>
</tr>
I want whatever is between:
description...
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....
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...
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 ...
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...
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 ...
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...
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...
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...
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...
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 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.
...
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...