![]() |
Regex confusion
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 |
Re: Regex confusion
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, trashman.horli...@btinternet.com 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 |
Re: Regex confusion
On 19 Feb, 16:07, "tfe" <tfeser...@gmail.com> 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, trashman.horli...@btinternet.com 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} ? |
Re: Regex confusion
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 |
Re: Regex confusion
On Feb 19, 10:55 am, trashman.horli...@btinternet.com 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 |
Re: Regex confusion
trashman.horlicks@btinternet.com 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 |
Re: Regex confusion
trashman.horlicks@btinternet.com <trashman.horlicks@btinternet.com> 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 tadmc@augustmail.com Perl programming Fort Worth, Texas |
| All times are GMT. The time now is 05:40 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.