Regular expression for exact match of a string
I want to match two passwords with regular expression. for example i have two inputs "123456" and "1234567" then the result should be not match(false). And when i have entered "123456" and "123456" then the result should be match(true).
I couldn't make the expression. Can any one help me plz.
regex
add a comment |
I want to match two passwords with regular expression. for example i have two inputs "123456" and "1234567" then the result should be not match(false). And when i have entered "123456" and "123456" then the result should be match(true).
I couldn't make the expression. Can any one help me plz.
regex
7
Why do you want regex in this case? Checking for (exact) equality should really be done without regex.
– Bart Kiers
Apr 22 '11 at 6:26
Because we look up how to replace text in a Bash script and get an answer that involves Perl and regex.
– sudo
Aug 1 '15 at 19:11
having the same issue a better solution ^(123456) will give the results that you want
– sdx11
Dec 21 '16 at 17:48
add a comment |
I want to match two passwords with regular expression. for example i have two inputs "123456" and "1234567" then the result should be not match(false). And when i have entered "123456" and "123456" then the result should be match(true).
I couldn't make the expression. Can any one help me plz.
regex
I want to match two passwords with regular expression. for example i have two inputs "123456" and "1234567" then the result should be not match(false). And when i have entered "123456" and "123456" then the result should be match(true).
I couldn't make the expression. Can any one help me plz.
regex
regex
edited Jul 27 '18 at 7:20
Wiktor Stribiżew
318k16139221
318k16139221
asked Apr 22 '11 at 6:24
ChirayuChirayu
1,59262244
1,59262244
7
Why do you want regex in this case? Checking for (exact) equality should really be done without regex.
– Bart Kiers
Apr 22 '11 at 6:26
Because we look up how to replace text in a Bash script and get an answer that involves Perl and regex.
– sudo
Aug 1 '15 at 19:11
having the same issue a better solution ^(123456) will give the results that you want
– sdx11
Dec 21 '16 at 17:48
add a comment |
7
Why do you want regex in this case? Checking for (exact) equality should really be done without regex.
– Bart Kiers
Apr 22 '11 at 6:26
Because we look up how to replace text in a Bash script and get an answer that involves Perl and regex.
– sudo
Aug 1 '15 at 19:11
having the same issue a better solution ^(123456) will give the results that you want
– sdx11
Dec 21 '16 at 17:48
7
7
Why do you want regex in this case? Checking for (exact) equality should really be done without regex.
– Bart Kiers
Apr 22 '11 at 6:26
Why do you want regex in this case? Checking for (exact) equality should really be done without regex.
– Bart Kiers
Apr 22 '11 at 6:26
Because we look up how to replace text in a Bash script and get an answer that involves Perl and regex.
– sudo
Aug 1 '15 at 19:11
Because we look up how to replace text in a Bash script and get an answer that involves Perl and regex.
– sudo
Aug 1 '15 at 19:11
having the same issue a better solution ^(123456) will give the results that you want
– sdx11
Dec 21 '16 at 17:48
having the same issue a better solution ^(123456) will give the results that you want
– sdx11
Dec 21 '16 at 17:48
add a comment |
5 Answers
5
active
oldest
votes
if you have a the input password in a variable and you want to match exactly 123456 then anchors will help you:
/^123456$/
in perl the test for matching the password would be something like
print "MATCH_OK" if ($input_pass=~/^123456$/);
EDIT:
bart kiers is right tho, why don't you use a strcmp() for this? every language has it in its own way
as a second thought, you may want to consider a safer authentication mechanism :)
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
add a comment |
In malfaux's answer '^' and '$' has been used to detect the beginning and the end of the text.
These are usually used to detect the beginning and the end of a line.
However this may be the correct way in this case.
But if you wish to match an exact word the more elegant way is to use 'b'. In this case following pattern will match the exact phrase'123456'.
/b123456b/
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
1
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
17
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
2
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
1
@0x1mason is correct thatbhttp://www.foo.comb
will matchhttp://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the^
(beginning) and$
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)
– twknab
Feb 11 '17 at 11:26
|
show 3 more comments
(?<![wd])abc(?![wd])
this makes sure that your match is not preceded by some character, number, or underscore and is not followed immediately by character or number, or underscore
so it will match "abc" in "abc", "abc.", "abc ", but not "4abc", nor "abcde"
1
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,w
matches digits as well as letters, so[wd]
is redundant.
– Alan Moore
Apr 17 '14 at 2:54
add a comment |
A more straight forward way is to check for equality
if string1 == string2
puts "match"
else
puts "not match"
end
however, if you really want to stick to regular expression,
string1 =~ /^123456$/
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
add a comment |
You may also try appending a space at the start and end of keyword: /s+123456s+/i
.
I was not able to get this method to work usings
via: regex101.com
– twknab
Feb 11 '17 at 11:29
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%2f5752829%2fregular-expression-for-exact-match-of-a-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
if you have a the input password in a variable and you want to match exactly 123456 then anchors will help you:
/^123456$/
in perl the test for matching the password would be something like
print "MATCH_OK" if ($input_pass=~/^123456$/);
EDIT:
bart kiers is right tho, why don't you use a strcmp() for this? every language has it in its own way
as a second thought, you may want to consider a safer authentication mechanism :)
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
add a comment |
if you have a the input password in a variable and you want to match exactly 123456 then anchors will help you:
/^123456$/
in perl the test for matching the password would be something like
print "MATCH_OK" if ($input_pass=~/^123456$/);
EDIT:
bart kiers is right tho, why don't you use a strcmp() for this? every language has it in its own way
as a second thought, you may want to consider a safer authentication mechanism :)
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
add a comment |
if you have a the input password in a variable and you want to match exactly 123456 then anchors will help you:
/^123456$/
in perl the test for matching the password would be something like
print "MATCH_OK" if ($input_pass=~/^123456$/);
EDIT:
bart kiers is right tho, why don't you use a strcmp() for this? every language has it in its own way
as a second thought, you may want to consider a safer authentication mechanism :)
if you have a the input password in a variable and you want to match exactly 123456 then anchors will help you:
/^123456$/
in perl the test for matching the password would be something like
print "MATCH_OK" if ($input_pass=~/^123456$/);
EDIT:
bart kiers is right tho, why don't you use a strcmp() for this? every language has it in its own way
as a second thought, you may want to consider a safer authentication mechanism :)
edited May 23 '17 at 12:34
Community♦
11
11
answered Apr 22 '11 at 6:29
user237419user237419
5,74432435
5,74432435
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
add a comment |
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
FYI: for me only ^123456$ works in the tester linked below.
– Tilo
Nov 6 '13 at 17:43
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
Thanks for the anchors, I knew that but completely didn't think about it :)
– vikingsteve
Dec 2 '15 at 11:47
add a comment |
In malfaux's answer '^' and '$' has been used to detect the beginning and the end of the text.
These are usually used to detect the beginning and the end of a line.
However this may be the correct way in this case.
But if you wish to match an exact word the more elegant way is to use 'b'. In this case following pattern will match the exact phrase'123456'.
/b123456b/
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
1
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
17
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
2
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
1
@0x1mason is correct thatbhttp://www.foo.comb
will matchhttp://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the^
(beginning) and$
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)
– twknab
Feb 11 '17 at 11:26
|
show 3 more comments
In malfaux's answer '^' and '$' has been used to detect the beginning and the end of the text.
These are usually used to detect the beginning and the end of a line.
However this may be the correct way in this case.
But if you wish to match an exact word the more elegant way is to use 'b'. In this case following pattern will match the exact phrase'123456'.
/b123456b/
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
1
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
17
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
2
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
1
@0x1mason is correct thatbhttp://www.foo.comb
will matchhttp://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the^
(beginning) and$
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)
– twknab
Feb 11 '17 at 11:26
|
show 3 more comments
In malfaux's answer '^' and '$' has been used to detect the beginning and the end of the text.
These are usually used to detect the beginning and the end of a line.
However this may be the correct way in this case.
But if you wish to match an exact word the more elegant way is to use 'b'. In this case following pattern will match the exact phrase'123456'.
/b123456b/
In malfaux's answer '^' and '$' has been used to detect the beginning and the end of the text.
These are usually used to detect the beginning and the end of a line.
However this may be the correct way in this case.
But if you wish to match an exact word the more elegant way is to use 'b'. In this case following pattern will match the exact phrase'123456'.
/b123456b/
edited Oct 17 '13 at 8:17
answered Oct 25 '12 at 9:41
prageethprageeth
5,20063459
5,20063459
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
1
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
17
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
2
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
1
@0x1mason is correct thatbhttp://www.foo.comb
will matchhttp://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the^
(beginning) and$
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)
– twknab
Feb 11 '17 at 11:26
|
show 3 more comments
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
1
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
17
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
2
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
1
@0x1mason is correct thatbhttp://www.foo.comb
will matchhttp://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the^
(beginning) and$
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)
– twknab
Feb 11 '17 at 11:26
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
Are you sure that it works in that way? ;) Please use a regex tester like this. Use "show match" button and you will see why it matches. BTW remember '.' is a special char and good to escape it. (and good to think twice before down voting :D ).
– prageeth
Sep 29 '13 at 3:16
1
1
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
If you think my answer is misleading or wrong, you still can post your own answer(as other people do) or place a comment under my post explaining your suggestion.
– prageeth
Jan 2 '14 at 5:03
17
17
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
Your answer is misleading and will cause many people serious problems. E.g., using your approach bhttp://www.foo.comb will match http://www.bar.com/?http://www.foo.com, which is most definitely not an exact match, as requested in the OP. This will cause serious problems for people working with URLs or passwords (which, again, is what the OP requested) that contain non-word characters. You should clarify your answer so others are not led astray.
– 0x1mason
Jan 2 '14 at 17:53
2
2
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
You'll have to explain. '.' is a red herring. bhttp://www.foo.comb still produces a match for http://www.bar.com/?http://www.foo.com. That's not what the OP wants.
– 0x1mason
Jan 7 '14 at 14:45
1
1
@0x1mason is correct that
bhttp://www.foo.comb
will match http://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the ^
(beginning) and $
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)– twknab
Feb 11 '17 at 11:26
@0x1mason is correct that
bhttp://www.foo.comb
will match http://www.foo.com=?http://www.foo.com
along with the URL as is. The first response, using the ^
(beginning) and $
(end) is the best method via these testers: regex101.com and regexr.com (the tester included in a link below is not very user friendly, these are much better)– twknab
Feb 11 '17 at 11:26
|
show 3 more comments
(?<![wd])abc(?![wd])
this makes sure that your match is not preceded by some character, number, or underscore and is not followed immediately by character or number, or underscore
so it will match "abc" in "abc", "abc.", "abc ", but not "4abc", nor "abcde"
1
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,w
matches digits as well as letters, so[wd]
is redundant.
– Alan Moore
Apr 17 '14 at 2:54
add a comment |
(?<![wd])abc(?![wd])
this makes sure that your match is not preceded by some character, number, or underscore and is not followed immediately by character or number, or underscore
so it will match "abc" in "abc", "abc.", "abc ", but not "4abc", nor "abcde"
1
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,w
matches digits as well as letters, so[wd]
is redundant.
– Alan Moore
Apr 17 '14 at 2:54
add a comment |
(?<![wd])abc(?![wd])
this makes sure that your match is not preceded by some character, number, or underscore and is not followed immediately by character or number, or underscore
so it will match "abc" in "abc", "abc.", "abc ", but not "4abc", nor "abcde"
(?<![wd])abc(?![wd])
this makes sure that your match is not preceded by some character, number, or underscore and is not followed immediately by character or number, or underscore
so it will match "abc" in "abc", "abc.", "abc ", but not "4abc", nor "abcde"
answered Apr 16 '14 at 19:01
AednaAedna
44145
44145
1
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,w
matches digits as well as letters, so[wd]
is redundant.
– Alan Moore
Apr 17 '14 at 2:54
add a comment |
1
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,w
matches digits as well as letters, so[wd]
is redundant.
– Alan Moore
Apr 17 '14 at 2:54
1
1
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,
w
matches digits as well as letters, so [wd]
is redundant.– Alan Moore
Apr 17 '14 at 2:54
The title of the question is misleading; he's trying to make sure two whole strings are exactly the same. Also,
w
matches digits as well as letters, so [wd]
is redundant.– Alan Moore
Apr 17 '14 at 2:54
add a comment |
A more straight forward way is to check for equality
if string1 == string2
puts "match"
else
puts "not match"
end
however, if you really want to stick to regular expression,
string1 =~ /^123456$/
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
add a comment |
A more straight forward way is to check for equality
if string1 == string2
puts "match"
else
puts "not match"
end
however, if you really want to stick to regular expression,
string1 =~ /^123456$/
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
add a comment |
A more straight forward way is to check for equality
if string1 == string2
puts "match"
else
puts "not match"
end
however, if you really want to stick to regular expression,
string1 =~ /^123456$/
A more straight forward way is to check for equality
if string1 == string2
puts "match"
else
puts "not match"
end
however, if you really want to stick to regular expression,
string1 =~ /^123456$/
answered Apr 22 '11 at 6:33
kurumikurumi
20k33344
20k33344
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
add a comment |
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
@Kurumi I'm trying to make java code that search for specific word in txt file and i want to use regx so could i use that pattern /^myword$/ with String.match(/^myword$/ ) to search for the word in that txt?
– Antwan
Mar 30 '14 at 0:45
add a comment |
You may also try appending a space at the start and end of keyword: /s+123456s+/i
.
I was not able to get this method to work usings
via: regex101.com
– twknab
Feb 11 '17 at 11:29
add a comment |
You may also try appending a space at the start and end of keyword: /s+123456s+/i
.
I was not able to get this method to work usings
via: regex101.com
– twknab
Feb 11 '17 at 11:29
add a comment |
You may also try appending a space at the start and end of keyword: /s+123456s+/i
.
You may also try appending a space at the start and end of keyword: /s+123456s+/i
.
edited Nov 7 '11 at 13:17
Benoit Garret
12.5k35261
12.5k35261
answered Nov 7 '11 at 11:36
Bhushan LodhaBhushan Lodha
3,86164884
3,86164884
I was not able to get this method to work usings
via: regex101.com
– twknab
Feb 11 '17 at 11:29
add a comment |
I was not able to get this method to work usings
via: regex101.com
– twknab
Feb 11 '17 at 11:29
I was not able to get this method to work using
s
via: regex101.com– twknab
Feb 11 '17 at 11:29
I was not able to get this method to work using
s
via: regex101.com– twknab
Feb 11 '17 at 11:29
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%2f5752829%2fregular-expression-for-exact-match-of-a-string%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
7
Why do you want regex in this case? Checking for (exact) equality should really be done without regex.
– Bart Kiers
Apr 22 '11 at 6:26
Because we look up how to replace text in a Bash script and get an answer that involves Perl and regex.
– sudo
Aug 1 '15 at 19:11
having the same issue a better solution ^(123456) will give the results that you want
– sdx11
Dec 21 '16 at 17:48