views:

28

answers:

1

I am learning regex (http://www.regular-expressions.info/), and trying to figure out how to match the part of the following string that is not: a word containing a q that is not followed by a u.

I've gotten this far, but cannot figure out how to reverse it properly. This regex is successful in finding the word. Now, I just need to figure out how to make it find the rest of the string except the word. suggestions?

(\w*(q(?!u))\w*)

JAZzY 23
JACKY 21 JIFFY 21 JUNKY 21 QUAKY 21 ZAPPY 21 ZAXES 21 ZINKY 21 ZIPPY 21
FURZY 20 HAFIZ 20 QUACK 20 QUAFF 20 QUICK 20 QUIFF 20 WOOZY 20
BOOZY 19 COZEY 19 CRAZY 19 ENZYM 19 FUZzY 19 HAMZA 19 JAMMY 19 JEMMY 19 JERKY 19 JIMMY 19 JIMPY 19 JOKEY 19 JUMPY 19 KUDZU 19 KYLIX 19 QOPHS 19 WHIZz 19 ZILCH 19 ZINCY 19 ZYMES 19
+1  A: 

You need to specify a language (JavaScript, PHP, etc.).

Here's one way to do it in JS: (See it in action at jsfiddle.)

var Str = 'JAZzY 23 '
        + 'JACKY 21 JIFFY 21 JUNKY 21 QUAKY 21 ZAPPY 21 ZAXES 21 ZINKY 21 '
        + 'ZIPPY 21 FURZY 20 HAFIZ 20 QUACK 20 QUAFF 20 QUICK 20 QUIFF 20 '
        + 'WOOZY 20 BOOZY 19 COZEY 19 CRAZY 19 ENZYM 19 FUZzY 19 HAMZA 19 '
        + 'JAMMY 19 JEMMY 19 JERKY 19 JIMMY 19 JIMPY 19 JOKEY 19 JUMPY 19 '
        + 'KUDZU 19 KYLIX 19 QOPHS 19 WHIZz 19 ZILCH 19 ZINCY 19 ZYMES 19 '
        + 'risque 69 risqay 86 Qu 19 Qa 33'
        ;

var Filtered = Str.replace (/\b\w*q(?!u)\w*\b/ig, "");
alert (Filtered);     
Brock Adams