Wildcard matching

J

jwcarlton

I'm trying to find and replace any non-alphanumeric character (or lack
thereof), followed by a specified word, followed by any other non-
alphanumeric character (or lack thereof).

Here's where I am so far, using "jason" as the specified word:

$comment =~ s/(\W)jason(\W)/$1*****$2/i;

Specifically, I want to catch things like " Jason" (notice the opening
whitespace), "<br>Jason!", "***Jason***", and "<br>Jason\n". I'm not
so concerned about underscores, which I understand aren't included in
\W.

Any suggestions?
 
A

azrazer

jwcarlton a écrit :
I'm trying to find and replace any non-alphanumeric character (or lack
thereof), followed by a specified word, followed by any other non-
alphanumeric character (or lack thereof).

Here's where I am so far, using "jason" as the specified word:

$comment =~ s/(\W)jason(\W)/$1*****$2/i;

Specifically, I want to catch things like " Jason" (notice the opening
whitespace), "<br>Jason!", "***Jason***", and "<br>Jason\n". I'm not
so concerned about underscores, which I understand aren't included in
\W.

Any suggestions?

Hello,
well i don't know if i understand well what you want to do... but i'll
give a try
if you want that
" Jason" => " *****"
"<br>Jason!" => "<br>*****!"
"***Jason***" => "***********"
"<br>Jason\n" => "<br>*****\n"
then your RE is correct, you just have to add a * quantifier after \W
(since "lack thereof" is OK), don't you ?

Cheers,
azra
 
W

Willem

jwcarlton wrote:
) I'm trying to find and replace any non-alphanumeric character (or lack
) thereof), followed by a specified word, followed by any other non-
) alphanumeric character (or lack thereof).

Wouldn't it be easier to just match word boundaries (you know, with \b )?

) Here's where I am so far, using "jason" as the specified word:
)
) $comment =~ s/(\W)jason(\W)/$1*****$2/i;

$comment =~ s/\bjason\b/*****/gi;


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 

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,214
Messages
2,571,112
Members
47,704
Latest member
DavidSuita

Latest Threads

Top