Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex confusion

Reply
Thread Tools

Regex confusion

 
 
trashman.horlicks@btinternet.com
Guest
Posts: n/a
 
      02-19-2007
Hi everyone,
I'm just starting to use regex to do some pattern matching but the
syntax is a little confusing. I'm using some of
the on-line regex checkers, but they all fail the following test:

regex /\bTest\s*,/i
look for Test, (or test, etc.)
- result: failure

I can't see anything wrong. Can anyone suggest whats amiss?

TIA

Paul

 
Reply With Quote
 
 
 
 
tfe
Guest
Posts: n/a
 
      02-19-2007
Hi,

You look to put a "," and you do not need.
Regex looks like that: /regex/ , or !regex! or #regex# , etc...
If you want to match the word "test", you juste have to put /\btest\b/
to match it.

The final option "i" comes after the separation :
/\btest\b/i

--
tfe
http://tfeserver.be

On 19 fév, 16:55, (E-Mail Removed) wrote:
> Hi everyone,
> I'm just starting to use regex to do some pattern matching but the
> syntax is a little confusing. I'm using some of
> the on-line regex checkers, but they all fail the following test:
>
> regex /\bTest\s*,/i
> look for Test, (or test, etc.)
> - result: failure
>
> I can't see anything wrong. Can anyone suggest whats amiss?
>
> TIA
>
> Paul



 
Reply With Quote
 
 
 
 
trashman.horlicks@btinternet.com
Guest
Posts: n/a
 
      02-19-2007
On 19 Feb, 16:07, "tfe" <(E-Mail Removed)> wrote:
> Hi,
>
> You look to put a "," and you do not need.
> Regex looks like that: /regex/ , or !regex! or #regex# , etc...
> If you want to match the word "test", you juste have to put /\btest\b/
> to match it.
>
> The final option "i" comes after the separation :
> /\btest\b/i
>
> --
> tfehttp://tfeserver.be
>
> On 19 fév, 16:55, (E-Mail Removed) wrote:
>
>
>
> > Hi everyone,
> > I'm just starting to use regex to do some pattern matching but the
> > syntax is a little confusing. I'm using some of
> > the on-line regex checkers, but they all fail the following test:

>
> > regex /\bTest\s*,/i
> > look for Test, (or test, etc.)
> > - result: failure

>
> > I can't see anything wrong. Can anyone suggest whats amiss?

>
> > TIA

>
> > Paul- Hide quoted text -

>
> - Show quoted text -



Thanks mate. I do actually need the "," to be a part of the regex
string.

By the way, looking at some examples of regex, I see constructs like
this:
[_\W]{0,3}
Isn't this just the same as [\w\W]{0,3} ?

 
Reply With Quote
 
trashman.horlicks@btinternet.com
Guest
Posts: n/a
 
      02-19-2007
Sorry, got confused. What I meant to say was: I am trying to construct
a regex that will check for
"test," (not the quotes)
"Test,"
"Test ,"
"test ,"
"Test ,"
plus any combination of upper and lower cases, plus whitespace between
"test" and ","

TIA

Paul

 
Reply With Quote
 
kens
Guest
Posts: n/a
 
      02-19-2007
On Feb 19, 10:55 am, (E-Mail Removed) wrote:
> Hi everyone,
> I'm just starting to use regex to do some pattern matching but the
> syntax is a little confusing. I'm using some of
> the on-line regex checkers, but they all fail the following test:
>
> regex /\bTest\s*,/i
> look for Test, (or test, etc.)
> - result: failure
>
> I can't see anything wrong. Can anyone suggest whats amiss?
>
> TIA
>
> Paul


Post actual code & sample input.
Such as:

use strict;
use warnings;

while (<DATA>)
{
chomp();
if ( /\bTest\s*,/i )
{
print "MATCHED: >>$_<<\n";
}
else
{
print "NOT MATCHED: >>$_<<\n";
}
}

__DATA__
test,
Test,
Test ,
test ,
Test ,

Ken

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      02-19-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
> By the way, looking at some examples of regex, I see constructs like
> this:
> [_\W]{0,3}
> Isn't this just the same as [\w\W]{0,3} ?


No. [_\W] says match an underscore or a non-word character. You could do the
same thing with the POSIX character class [^[:alnum:]].

[\w\W] matches *any* character, as would [\s\S] or [\d\D] or (?s:.).




John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      02-20-2007
(E-Mail Removed) <(E-Mail Removed)> wrote:

> I'm just starting to use regex to do some pattern matching



You need *two* pieces of information to analyse why a pattern is
matching or not.

You need the regular expression, and you need the string that the
regular expression is to be matched against.


> regex /\bTest\s*,/i



There is the regular expression.


> I can't see anything wrong.



Neither can we, because we cannot see what is in $_


> Can anyone suggest whats amiss?



Probably the string does not match the pattern somehow. (heh)


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Regex confusion... guthrie Perl Misc 6 09-28-2007 05:04 AM
Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine? =?Utf-8?B?SmViQnVzaGVsbA==?= ASP .Net 2 10-22-2005 02:43 PM
regex confusion John Hunter Python 8 12-09-2003 05:23 PM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments