chaitu
chaitu

Reputation: 1206

regex for matching particular word in whole sentence using perl

I want a regex in perl that can strip the word in capitals from the given sentence "Device from XML database". I can say that the whole sentence can change in future including the spaces present now. Only the "xml" word is fixed and all the stuff around it is volatile. So i want a strong regex that can withstand any changes in number of spaces and words before/after "xml" word.

Upvotes: 0

Views: 1156

Answers (2)

lecstor
lecstor

Reputation: 5707

$string = "Device from XML database"; $string =~ s/\bXML\b\s//;

That'll grab one space after XML as well..

Upvotes: 2

cdarke
cdarke

Reputation: 44344

Try using the word boundary anchor \b: \bXML\b

Upvotes: 0

Related Questions