Regular expression imesh and timesheet

T

TG

hello,

i wan't to write a regular expression who match imesh but no match
tIMESHeet. How can i do that ?



thank you
 
T

TG

Helgi said:
You mean, match a single word only?

Use the boundary matching tag \b

print "Match!" if /\bimesh\b/;


not exactly, here an example of that i want :


imesh -> match
timessheet -> not match
myimeshsite -> match

Thank you
 
G

Glenn Jackman

TG said:
hello,

i wan't to write a regular expression who match imesh but no match
tIMESHeet. How can i do that ?

A simple way is to just use 2 expressions. There's surely a clever RE,
but it may not improve readability.

if ($str =~ /imesh/i and $str !~ /timesheet/i) {
# do something
}
 
T

TG

Glenn said:
A simple way is to just use 2 expressions. There's surely a clever RE,
but it may not improve readability.

if ($str =~ /imesh/i and $str !~ /timesheet/i) {
# do something
}
sorry, but i want one expression
 
J

Jay Tilton

: Glenn Jackman wrote:
: >
: >>i wan't to write a regular expression who match imesh but no match
: >>tIMESHeet. How can i do that ?
: >
: > A simple way is to just use 2 expressions. There's surely a clever RE,
: > but it may not improve readability.
: >
: > if ($str =~ /imesh/i and $str !~ /timesheet/i) {
: > # do something
: > }
: >
: sorry, but i want one expression

Why?

Do you have a subroutine that only accepts a regex argument?
Modifying that subroutine may be a better idea than trying to conform
to its expectations.

Are you planning to use a Perl regex in something besides a Perl
program? You might get something you can't use.

Anyway,

m/(?:(?<=(t))|(?<!t))imesh(?(1)(?!eet))/
^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^
Man, that's f'ed up, but it's the best I could come up with to make
the conditional pattern at the end work, without spending too much
time on it.

Two match operations is definitely the less nauseating approach.
 

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

Forum statistics

Threads
474,102
Messages
2,570,641
Members
47,245
Latest member
LatiaMario

Latest Threads

Top