开发者

Regex get parts of string that do not match pattern

开发者 https://www.devze.com 2023-01-19 07:47 出处:网络
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 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


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);     
0

精彩评论

暂无评论...
验证码 换一张
取 消