Regex for selecting words ending in 'ing' unless
I want to select words ending in with a regular expression, but I want exclude words that end in thing
. For example:
everything
running
catching
nothing
Of these words, running and catching should be selected, everything and nothing should be excluded.
I've tried the following:
.+ing$
But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.
Solutions that work in Python or R would be helpful.
regex regex-negation regex-lookarounds
add a comment |
I want to select words ending in with a regular expression, but I want exclude words that end in thing
. For example:
everything
running
catching
nothing
Of these words, running and catching should be selected, everything and nothing should be excluded.
I've tried the following:
.+ing$
But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.
Solutions that work in Python or R would be helpful.
regex regex-negation regex-lookarounds
Usebw*ingb(?<!thing)
orbw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11
add a comment |
I want to select words ending in with a regular expression, but I want exclude words that end in thing
. For example:
everything
running
catching
nothing
Of these words, running and catching should be selected, everything and nothing should be excluded.
I've tried the following:
.+ing$
But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.
Solutions that work in Python or R would be helpful.
regex regex-negation regex-lookarounds
I want to select words ending in with a regular expression, but I want exclude words that end in thing
. For example:
everything
running
catching
nothing
Of these words, running and catching should be selected, everything and nothing should be excluded.
I've tried the following:
.+ing$
But that selects everything. I'm thinking look aheads/look arounds could be the solution, but I haven't been able to get one that works.
Solutions that work in Python or R would be helpful.
regex regex-negation regex-lookarounds
regex regex-negation regex-lookarounds
asked Nov 12 '18 at 21:08
Todd Shannon
537
537
Usebw*ingb(?<!thing)
orbw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11
add a comment |
Usebw*ingb(?<!thing)
orbw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11
Use
bw*ingb(?<!thing)
or bw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11
Use
bw*ingb(?<!thing)
or bw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11
add a comment |
3 Answers
3
active
oldest
votes
In python you can use negative lookbehind assertion as this:
^.*(?<!th)ing$
RegEx Demo
(?<!th)
is negative lookbehind expression that will fail the match if th
comes before ing
at the end of string.
Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:
w+(?<!th)ingb
add a comment |
Something like bw+(?<!th)ingb
maybe.
add a comment |
You might also use a negative lookahead (?!
to assert that what is on the right is not 0+ times a word character followed by thing
and a word boundary:
b(?!w*thingb)w*ingb
Regex demo | Python demo
Think you need to adding
to the end of your regex so that it does not match words that do not end in "ing".
– benvc
Nov 12 '18 at 21:17
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270128%2fregex-for-selecting-words-ending-in-ing-unless%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In python you can use negative lookbehind assertion as this:
^.*(?<!th)ing$
RegEx Demo
(?<!th)
is negative lookbehind expression that will fail the match if th
comes before ing
at the end of string.
Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:
w+(?<!th)ingb
add a comment |
In python you can use negative lookbehind assertion as this:
^.*(?<!th)ing$
RegEx Demo
(?<!th)
is negative lookbehind expression that will fail the match if th
comes before ing
at the end of string.
Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:
w+(?<!th)ingb
add a comment |
In python you can use negative lookbehind assertion as this:
^.*(?<!th)ing$
RegEx Demo
(?<!th)
is negative lookbehind expression that will fail the match if th
comes before ing
at the end of string.
Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:
w+(?<!th)ingb
In python you can use negative lookbehind assertion as this:
^.*(?<!th)ing$
RegEx Demo
(?<!th)
is negative lookbehind expression that will fail the match if th
comes before ing
at the end of string.
Note that if you are matching words that are not on separate lines then instead of anchors use word boundaries as:
w+(?<!th)ingb
answered Nov 12 '18 at 21:11
anubhava
520k46316390
520k46316390
add a comment |
add a comment |
Something like bw+(?<!th)ingb
maybe.
add a comment |
Something like bw+(?<!th)ingb
maybe.
add a comment |
Something like bw+(?<!th)ingb
maybe.
Something like bw+(?<!th)ingb
maybe.
answered Nov 12 '18 at 21:11
sln
26.3k31636
26.3k31636
add a comment |
add a comment |
You might also use a negative lookahead (?!
to assert that what is on the right is not 0+ times a word character followed by thing
and a word boundary:
b(?!w*thingb)w*ingb
Regex demo | Python demo
Think you need to adding
to the end of your regex so that it does not match words that do not end in "ing".
– benvc
Nov 12 '18 at 21:17
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
add a comment |
You might also use a negative lookahead (?!
to assert that what is on the right is not 0+ times a word character followed by thing
and a word boundary:
b(?!w*thingb)w*ingb
Regex demo | Python demo
Think you need to adding
to the end of your regex so that it does not match words that do not end in "ing".
– benvc
Nov 12 '18 at 21:17
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
add a comment |
You might also use a negative lookahead (?!
to assert that what is on the right is not 0+ times a word character followed by thing
and a word boundary:
b(?!w*thingb)w*ingb
Regex demo | Python demo
You might also use a negative lookahead (?!
to assert that what is on the right is not 0+ times a word character followed by thing
and a word boundary:
b(?!w*thingb)w*ingb
Regex demo | Python demo
edited Nov 12 '18 at 21:48
answered Nov 12 '18 at 21:15
The fourth bird
20.8k71326
20.8k71326
Think you need to adding
to the end of your regex so that it does not match words that do not end in "ing".
– benvc
Nov 12 '18 at 21:17
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
add a comment |
Think you need to adding
to the end of your regex so that it does not match words that do not end in "ing".
– benvc
Nov 12 '18 at 21:17
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
Think you need to add
ing
to the end of your regex so that it does not match words that do not end in "ing".– benvc
Nov 12 '18 at 21:17
Think you need to add
ing
to the end of your regex so that it does not match words that do not end in "ing".– benvc
Nov 12 '18 at 21:17
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
@benvc You are correct, thank you!
– The fourth bird
Nov 12 '18 at 21:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270128%2fregex-for-selecting-words-ending-in-ing-unless%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Use
bw*ingb(?<!thing)
orbw*(?<!th)ingb
– Wiktor Stribiżew
Nov 12 '18 at 21:11