How to search for alphanumeric word before or after a keyword in perl?

Posted by aliocee on Stack Overflow See other posts from Stack Overflow or by aliocee
Published on 2012-10-02T03:35:03Z Indexed on 2012/10/02 3:37 UTC
Read the original article Hit count: 351

Filed under:

I have sentences as shown in the below examples:

$sen1 = "The quick brown fox jump KEYWORD over123 the3 lazy dog, fox is quick";

$sen2 = "The quick brown fox jump123 KEYWORD over the lazy dog, fox is quick"; 

i want to use the keyword 'KEYWORD' as my search string to extract the alphanumeric words before and after the search string using Perl regular expression.

sample output:

over123

jump123

NB: The word 'the3' is left out because i'm only searching for alphanumeric words exactly before or after the 'KEYWORD'.

Thanks

© Stack Overflow or respective owner

Related posts about perl