Website Toolbox Pro

Need Help With Regular Expression?

Javascript, Regular Expressions Comments »
Hi all,
I need help with Regex (Regular Expression).

For example there's a webpage on a website, and I want to get the first link on that webpage, after certain words.
e.g:
"Website from http://www.website.com/blabla.php?var=blabla&se=3290 is awesome"

question: how to get the link only
http://www.website.com/blabla.php?var=blabla&se=3290

Here's a solution using javascript:

var strW = "website from http://www.website. com/blabla.php?var=blabla&se=3290 is awesome";
var regW = /(website|Website).* (http[^\s]*).* (awesome|great)/;
if (regW.test(strW)) alert (RegExp.$2);

Add/delete the key words preceding and following the URL. The URL is referenced using RegExp.$2

Regex Help?

Regular Expressions Comments »
What would be a string to replace:

This is $1.00. Ain't that nice
$1.00 for this stuff.
Buy this now for $1.00

with the format:

$1.00 {rest of the stuff from string}
so the output would be.
$1.00 This is . Ain't that nice
$1.00 for this stuff.
$1.00 Buy this now for

Continue reading Regex Help? »

Regular Expression For Validating A String Which Contains Only Characters?

Javascript, Regular Expressions Comments »
Regular expression for validating a string which contains only characters in Javascript?

Continue reading Regular Expression For Validating A String Which Contains Only Characters? »

Struggling With Perl Regular Expression

Regular Expressions Comments »
I have a series of words followed by a pre-determined marker (say the letter x in this case) contained in a string.

$contents = 'test1x     test!x     test2x';

There is a need to extract a list of those words that contain only alphanumeric characters plus the marker, ‘x’. So obviously “test!x” not wanted.

If I run the following regex:

@filtered_list =
(
  $contents =~  /(?:[\w]+) /g
);

Then I get the following list returned:

("test1x", "x", "test2x")

as opposed to a required list of

("test1x", "test2x")

The problem is with the 2nd item – it fails on the character “!” and just moves on to the next character when I really want to just stop right there and not return anything for this word.

I know I am just not seeing something completely obvious…

Thank you.

Continue reading Struggling With Perl Regular Expression »

Javascript: Variables Within Regex?

Javascript, Regular Expressions Comments »
Is it possible to use a variable within a regular expression declaration? For example:

var findThs="test123";
var mystring = "This is some test123 text";
var result = myString.match(/findthis(?:,| |$)/);

This doesnt return a result since findthis is being interpreted as text rather than a variable. I want its contents to be inserted into the regex expression.

Continue reading Javascript: Variables Within Regex? »