regex

Error when using Java String split

HI All, I've been using the basic split for a while - where I just parse out a string into an array based on a simple token like " " or ",". So of course a customer tries this: \\.br\ which fails miserably. I need to parse to an array of lines. The string for example looks like this: "LINE 1\\.br\\LINE 2\\.br\\LINE 3\\.br\\LINE 4\\....

Alternative for my preg_replace code

Here is my code... basically it finds any page-NUMBER- within a variable and then replaces it with a page url from an array $content_text = preg_replace("/page-(\d+)-/sie", '$pageurl[$1]', $content_text); It works a treat until the NUMBER it finds isn't in the array and it returns an error... Is there another efficient way I could do...

How can I print lines that match a pattern in Perl?

Assuming file.txt has just one sentence per line as follows: John Depp is a great guy. He is very inteligent. He can do anything. Come and meet John Depp. The Perl code is as follows:- open ( FILE, "file.txt" ) || die "can't open file!"; @lines = <FILE>; close (FILE); $string = "John Depp"; foreach $line (@lines) { if ($lin...

get particular string using regex in java

i want how to code for get only link from string using regex or anyothers. here the following is java code: String aas = "window.open("+"\""+"http://www.example.com/jscript/jex5.htm"+"\""+")"+"\n"+"window.open("+"\""+"http://www.example.com/jscript/jex5.htm"+"\""+")"; how to get the link http://www.example.com/jscript/jex5.htm than...

Java splitting string by custom regex match

I am completely new to regular expressions so I'm looking for a bit of help here. I am compiling under JDK 1.5 Take this line as an example that I read from standard input: ab:Some string po:bubblegum What I would like to do is split by the two characters and colon. That is, once the line is split and put into a string array, these ...

write regex code in java for following data

<table> <tr> <td style="width:180px"> <a href="/search?q=user:240698+[java]" class="post-tag" title="show all posts by this user in 'java'">java</a><span class="item-multiplier">&times;&nbsp;176</span><br> <a href="/search?q=user:240698+[servlets]" class="post-tag" title="show all posts by this user in 'servlets'">servlets</a><sp...

finding a string of random characters (with possible errors) within a large string of random characters

I am trying to search a large string w/o spaces for a smaller string of characters. using regex I can easily find perfect matches but I can't figure out how to find partial matches. by partial matches i mean one or two extra characters in the string or one or two characters that have been changed, or one of each. the first and last chara...

Selecting a specific div from a extern webpage using CURL

Hi can anyone help me how to select a specific div from the content of a webpage. Let's say i want to get the div with id="wrapper_content" from webpage http://www.test.com/page3.php. My current code looks something like this: (not working) //REG EXP. $s_searchFor = '@^/.dont know what to put here..@ui'; //CURL $ch = curl_init()...

How do I convert CamelCase into human-readable names in Java?

I'd like to write a method that converts CamelCase into a human-readable name. Here's the test case: public void testSplitCamelCase() { assertEquals("lowercase", splitCamelCase("lowercase")); assertEquals("Class", splitCamelCase("Class")); assertEquals("My Class", splitCamelCase("MyClass")); assertEquals("HTML", splitCa...

Split a HTML string into two strings without slicing through a word and preserving HTML in PHP

I'm looking for a way to split a string containing HTML in to two halves. Requirements: Split a string by a number of chars Must not split in the middle of a word Must not include HTML chars when calculating where to split the string For example take the following string: <p>This is a test string that contains <strong>HTML</strong> ...

Find Last Index Of by Regex in Java

Hello, i have a string %/O^/O%/O. I want to find the last / to split the string. First attemp was: \/[POL]$ but that gets it inclusive the "O" which is obvious. Has somebody a tip? ...

Why am I getting illegal escape characters with regexp in Java?

I'm working on a simply password strength checker and i can not success applying regular expressions. In different resources different kinds of regular expressions are defined. i also find javascript regular expressions but had some problems to adapt. First, these are the regular expressions i need for JAVA: at least one lower case le...

Sed substitution not doing what I want and think it should do

I have am trying to use sed to get some info that is encoded within the path of a file which is passed as a parameter to my script (Bourne sh, if it matters). From this example path, I'd like the result to be 8 PATH=/foo/bar/baz/1-1.8/sing/song I first got the regex close by using sed as grep: echo $PATH | sed -n -e "/^.*\/1-1\.\([0...

Regular expression to convert ul to textformat and back, with a different attribute value for first tag (VB.NET)

Hi, This is a related to a previous question I have asked here, see the link below for a brief description as to why I am trying to do this. Regular expression from font to span (size and colour) and back (VB.NET) Basically I need a regex replace function (or if this can be done in pure VB then that's fine) to convert all ul tags in a...

JavaScript To Strip Page For URL

We have a javascript function we use to track page stats internally. However, the URLs it reports many times include the page numbers for search results pages which we would rather not be reported. The pages that are reports are of the form: http://www.test.com/directory1/2 http://www.test.com/directory1/subdirectory1/15 http://www.test...

When writing a form submit to a file, strip line breaks and commas

I have a form with a textarea in it. I log the results to a text file on the server, but I would like to strip out any line breaks a user would put in the textarea, as well as any commas that would interfere with importing the comma-delimited log text file into Excel or something for later use. I think this has to do with regex, but I'm...

Jakarta Regexp 1.5 Backreferences?

Why does this match: String str = "099.9 102.2" + (char) 0x0D; RE re = new RE("^([0-9]{3}.[0-9]) ([0-9]{3}.[0-9])\r$"); System.out.println(re.match(str)); But this does not: String str = "099.9 102.2" + (char) 0x0D; RE re = new RE("^([0-9]{3}.[0-9]) \1\r$"); System.out.println(re.match(str)); The back references do...

PHP preg_replace - Very quick question

Masters of regular expressions, please help! See this string: $string = "http://www.url.com/?fieldA=123&amp;fieldB=456&amp;fieldC=789"; Assuming "fieldB" always has a positive non-decimal numerical value (but not necessarily three digits long), what preg_replace command do I need to remove it completely, such that the string will the...

Regex matching very slow

I am trying to parse a PDF to extract the text from it (please don't suggest any libraries to do this, as this is part of learning the format). I have already handled deflating it to put it in the alphanumeric format. I now need to extract the text from the text blocks. So, my current pattern is BT.*?\((.*?)\).*?ET (with DOTMATCHALL set)...

How do I check if a scalar has a compiled regex in it with Perl?

Let's say I have a subroutine/method that a user can call to test some data that (as an example) might look like this: sub test_output { my ($self, $test) = @_; my $output = $self->long_process_to_get_data(); if ($output =~ /\Q$test/) { $self->assert_something(); } else { $self->do_something_else(); ...