Regex confusion

T

trashman.horlicks

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
 
T

tfe

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
 
T

trashman.horlicks

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





- 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} ?
 
T

trashman.horlicks

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
 
K

kens

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
 
J

John W. Krahn

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
 
T

Tad McClellan

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top