How can I match with regular expression?
What I really want to do is to match all words what ever substring contain.it is working but I tried with one word.I don't want to match that string but any extra char added to that string I want to match.Like below
^(?!wallet)(car|cell phone|marbles|wallet|.*?wall.*)$
In above example I dont want to match with wallet but able to match with wallett.is it possible?
java regex
|
show 3 more comments
What I really want to do is to match all words what ever substring contain.it is working but I tried with one word.I don't want to match that string but any extra char added to that string I want to match.Like below
^(?!wallet)(car|cell phone|marbles|wallet|.*?wall.*)$
In above example I dont want to match with wallet but able to match with wallett.is it possible?
java regex
regex is not a language...Mr Ivar.It is a concept.No need to add that one.it is not necessary
– Shiva Goud A
Jan 3 at 11:45
3
Tags are not restricted to languages. Tags represent, relevant to the question, topics, not explicitely languages used. Besides, can you please show us a Minimal, Complete, and Verifiable example? How are you using that regex? What is the desired output for a given input? The question is slightly unclear
– Fureeish
Jan 3 at 11:46
I want to match waletttt.... String beacuse we are checking with contain ".*wall.*"but I don't want to match with "wallet" because we are subtracting that word
– Shiva Goud A
Jan 3 at 11:52
1
Thank you Ivar.its working
– Shiva Goud A
Jan 3 at 12:07
2
@Ivar what ever Nagaraju Thalluri mentioned in that we are not able to see * symbol at contains condition.
– Shiva Goud A
Jan 4 at 7:11
|
show 3 more comments
What I really want to do is to match all words what ever substring contain.it is working but I tried with one word.I don't want to match that string but any extra char added to that string I want to match.Like below
^(?!wallet)(car|cell phone|marbles|wallet|.*?wall.*)$
In above example I dont want to match with wallet but able to match with wallett.is it possible?
java regex
What I really want to do is to match all words what ever substring contain.it is working but I tried with one word.I don't want to match that string but any extra char added to that string I want to match.Like below
^(?!wallet)(car|cell phone|marbles|wallet|.*?wall.*)$
In above example I dont want to match with wallet but able to match with wallett.is it possible?
java regex
java regex
edited Jan 3 at 11:42
Ivar
2,878113241
2,878113241
asked Jan 3 at 11:41
Shiva Goud AShiva Goud A
177314
177314
regex is not a language...Mr Ivar.It is a concept.No need to add that one.it is not necessary
– Shiva Goud A
Jan 3 at 11:45
3
Tags are not restricted to languages. Tags represent, relevant to the question, topics, not explicitely languages used. Besides, can you please show us a Minimal, Complete, and Verifiable example? How are you using that regex? What is the desired output for a given input? The question is slightly unclear
– Fureeish
Jan 3 at 11:46
I want to match waletttt.... String beacuse we are checking with contain ".*wall.*"but I don't want to match with "wallet" because we are subtracting that word
– Shiva Goud A
Jan 3 at 11:52
1
Thank you Ivar.its working
– Shiva Goud A
Jan 3 at 12:07
2
@Ivar what ever Nagaraju Thalluri mentioned in that we are not able to see * symbol at contains condition.
– Shiva Goud A
Jan 4 at 7:11
|
show 3 more comments
regex is not a language...Mr Ivar.It is a concept.No need to add that one.it is not necessary
– Shiva Goud A
Jan 3 at 11:45
3
Tags are not restricted to languages. Tags represent, relevant to the question, topics, not explicitely languages used. Besides, can you please show us a Minimal, Complete, and Verifiable example? How are you using that regex? What is the desired output for a given input? The question is slightly unclear
– Fureeish
Jan 3 at 11:46
I want to match waletttt.... String beacuse we are checking with contain ".*wall.*"but I don't want to match with "wallet" because we are subtracting that word
– Shiva Goud A
Jan 3 at 11:52
1
Thank you Ivar.its working
– Shiva Goud A
Jan 3 at 12:07
2
@Ivar what ever Nagaraju Thalluri mentioned in that we are not able to see * symbol at contains condition.
– Shiva Goud A
Jan 4 at 7:11
regex is not a language...Mr Ivar.It is a concept.No need to add that one.it is not necessary
– Shiva Goud A
Jan 3 at 11:45
regex is not a language...Mr Ivar.It is a concept.No need to add that one.it is not necessary
– Shiva Goud A
Jan 3 at 11:45
3
3
Tags are not restricted to languages. Tags represent, relevant to the question, topics, not explicitely languages used. Besides, can you please show us a Minimal, Complete, and Verifiable example? How are you using that regex? What is the desired output for a given input? The question is slightly unclear
– Fureeish
Jan 3 at 11:46
Tags are not restricted to languages. Tags represent, relevant to the question, topics, not explicitely languages used. Besides, can you please show us a Minimal, Complete, and Verifiable example? How are you using that regex? What is the desired output for a given input? The question is slightly unclear
– Fureeish
Jan 3 at 11:46
I want to match waletttt.... String beacuse we are checking with contain ".*wall.*"but I don't want to match with "wallet" because we are subtracting that word
– Shiva Goud A
Jan 3 at 11:52
I want to match waletttt.... String beacuse we are checking with contain ".*wall.*"but I don't want to match with "wallet" because we are subtracting that word
– Shiva Goud A
Jan 3 at 11:52
1
1
Thank you Ivar.its working
– Shiva Goud A
Jan 3 at 12:07
Thank you Ivar.its working
– Shiva Goud A
Jan 3 at 12:07
2
2
@Ivar what ever Nagaraju Thalluri mentioned in that we are not able to see * symbol at contains condition.
– Shiva Goud A
Jan 4 at 7:11
@Ivar what ever Nagaraju Thalluri mentioned in that we are not able to see * symbol at contains condition.
– Shiva Goud A
Jan 4 at 7:11
|
show 3 more comments
2 Answers
2
active
oldest
votes
You can use it like this:
^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
This doesn't match "wallett" as asked in the question. Also what's the|nag
for?
– Ivar
Jan 3 at 12:23
1
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
1
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
add a comment |
The problem with your Regex is that the negative lookahead will match everything starting with "wallet". "wallett" also starts with "wallet" so it will be matched and therefore (as it is a negative lookahead) excluded.
You can fix that by adding the $
anchor to be sure it only matches wallet with nothing after it.
So your regex will become this:
^(?!wallet$)(car|cell phone|marbles|.*?wall.*)$
(Note that the latter "wallet" in your regex can be removed as it is equal to the negative lookahead so it will never match.)
You can see a live example here.
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%2f54021589%2fhow-can-i-match-with-regular-expression%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use it like this:
^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
This doesn't match "wallett" as asked in the question. Also what's the|nag
for?
– Ivar
Jan 3 at 12:23
1
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
1
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
add a comment |
You can use it like this:
^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
This doesn't match "wallett" as asked in the question. Also what's the|nag
for?
– Ivar
Jan 3 at 12:23
1
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
1
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
add a comment |
You can use it like this:
^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
You can use it like this:
^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
edited Jan 4 at 12:18
Ivar
2,878113241
2,878113241
answered Jan 3 at 12:09
Nagaraju ThalluriNagaraju Thalluri
548
548
This doesn't match "wallett" as asked in the question. Also what's the|nag
for?
– Ivar
Jan 3 at 12:23
1
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
1
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
add a comment |
This doesn't match "wallett" as asked in the question. Also what's the|nag
for?
– Ivar
Jan 3 at 12:23
1
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
1
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
This doesn't match "wallett" as asked in the question. Also what's the
|nag
for?– Ivar
Jan 3 at 12:23
This doesn't match "wallett" as asked in the question. Also what's the
|nag
for?– Ivar
Jan 3 at 12:23
1
1
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
Also it is always recommended too add an explanation as of why your code/expression fixed the problem. Questions here are not only for the person asking, but for any future visitors as well.
– Ivar
Jan 3 at 12:25
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
^(?!^wallet$|^nag$)(car|cell phone|marbles|wallet|.*?wall.*|.*?ag.*)$ try this Ivar.its work fine.Shiva Goud A ask only one negate value but I gave multiple.If he want then he'll accept.
– Nagaraju Thalluri
Jan 4 at 6:42
1
1
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
Not required those caps @NagarajuThalluri.u can use directly ^(?!(wallet|nag)$)(car|cell phone|marbles|wallet|.*?wall.*)$
– Shiva Goud A
Jan 4 at 7:12
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
@NagarajuThalluri Like I said, you should add an explanation of why your code/expression fixed the problem. It nice that OP solved their problem, but we expect high quality and good explanations for future visitors as well. Please edit your question accordingly.
– Ivar
Jan 4 at 12:19
add a comment |
The problem with your Regex is that the negative lookahead will match everything starting with "wallet". "wallett" also starts with "wallet" so it will be matched and therefore (as it is a negative lookahead) excluded.
You can fix that by adding the $
anchor to be sure it only matches wallet with nothing after it.
So your regex will become this:
^(?!wallet$)(car|cell phone|marbles|.*?wall.*)$
(Note that the latter "wallet" in your regex can be removed as it is equal to the negative lookahead so it will never match.)
You can see a live example here.
add a comment |
The problem with your Regex is that the negative lookahead will match everything starting with "wallet". "wallett" also starts with "wallet" so it will be matched and therefore (as it is a negative lookahead) excluded.
You can fix that by adding the $
anchor to be sure it only matches wallet with nothing after it.
So your regex will become this:
^(?!wallet$)(car|cell phone|marbles|.*?wall.*)$
(Note that the latter "wallet" in your regex can be removed as it is equal to the negative lookahead so it will never match.)
You can see a live example here.
add a comment |
The problem with your Regex is that the negative lookahead will match everything starting with "wallet". "wallett" also starts with "wallet" so it will be matched and therefore (as it is a negative lookahead) excluded.
You can fix that by adding the $
anchor to be sure it only matches wallet with nothing after it.
So your regex will become this:
^(?!wallet$)(car|cell phone|marbles|.*?wall.*)$
(Note that the latter "wallet" in your regex can be removed as it is equal to the negative lookahead so it will never match.)
You can see a live example here.
The problem with your Regex is that the negative lookahead will match everything starting with "wallet". "wallett" also starts with "wallet" so it will be matched and therefore (as it is a negative lookahead) excluded.
You can fix that by adding the $
anchor to be sure it only matches wallet with nothing after it.
So your regex will become this:
^(?!wallet$)(car|cell phone|marbles|.*?wall.*)$
(Note that the latter "wallet" in your regex can be removed as it is equal to the negative lookahead so it will never match.)
You can see a live example here.
edited Jan 3 at 12:22
answered Jan 3 at 12:12
IvarIvar
2,878113241
2,878113241
add a comment |
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.
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%2f54021589%2fhow-can-i-match-with-regular-expression%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
regex is not a language...Mr Ivar.It is a concept.No need to add that one.it is not necessary
– Shiva Goud A
Jan 3 at 11:45
3
Tags are not restricted to languages. Tags represent, relevant to the question, topics, not explicitely languages used. Besides, can you please show us a Minimal, Complete, and Verifiable example? How are you using that regex? What is the desired output for a given input? The question is slightly unclear
– Fureeish
Jan 3 at 11:46
I want to match waletttt.... String beacuse we are checking with contain ".*wall.*"but I don't want to match with "wallet" because we are subtracting that word
– Shiva Goud A
Jan 3 at 11:52
1
Thank you Ivar.its working
– Shiva Goud A
Jan 3 at 12:07
2
@Ivar what ever Nagaraju Thalluri mentioned in that we are not able to see * symbol at contains condition.
– Shiva Goud A
Jan 4 at 7:11