Javascript match a string which start with a specific char from the set of chars and end with same char using Regular ExpressionWhat is the best regular expression to check if a string is a valid URL?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular expression to stop at first matchHow to match “anything up until this sequence of characters” in a regular expression?javascript to match string start with “ and end with ”; and anything in between?JavaScript Regex finding all substrings matching the starting and ending patternmatching words starting and ending with same letterregex matching for string with character limit, specific start characters, and terminationMatch the same start and end character of a string with Regex
Why do the non-leaf Nodes of Merkle tree need to be hashed?
Why was wildfire not used during the Battle of Winterfell?
Would encrypting a database protect against a compromised admin account?
Why do unstable nuclei form?
Has there been evidence of any other gods?
Thesis' "Future Work" section – is it acceptable to omit personal involvement in a mentioned project?
Watching the game, having a puzzle
How to efficiently lower your karma
Has magnetic core memory been used beyond the Moon?
What do "KAL." and "A.S." stand for in this inscription?
Was there a contingency plan in place if Little Boy failed to detonate?
Is this state of Earth possible, after humans left for a million years?
Pre-1993 comic in which Wolverine's claws were turned to rubber?
Why does it take longer to fly from London to Xi'an than to Beijing
Is it a good idea to copy a trader when investing?
Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?
Getting a error after using setState with a promise
Can a surprised creature fall prone voluntarily on their turn?
Translation of the latin word 'sit' in Thomas Aquinas' works
What's the difference between const array and static const array in C/C++
How can I avoid subordinates and coworkers leaving work until the last minute, then having no time for revisions?
How to make a language evolve quickly?
Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech
Peculiarities in low dimensions or low order or etc
Javascript match a string which start with a specific char from the set of chars and end with same char using Regular Expression
What is the best regular expression to check if a string is a valid URL?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular expression to stop at first matchHow to match “anything up until this sequence of characters” in a regular expression?javascript to match string start with “ and end with ”; and anything in between?JavaScript Regex finding all substrings matching the starting and ending patternmatching words starting and ending with same letterregex matching for string with character limit, specific start characters, and terminationMatch the same start and end character of a string with Regex
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.
so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:
function regexVar()
var re = /(.).*1/
return re;
console.log("obcdo".test(s));
let suppose the specific set of chars is the vowel
(a, e, i, o, u)
in this case:
abcd ----> false
obcdo ----> true
ixyz ----> false
javascript regex
add a comment |
I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.
so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:
function regexVar()
var re = /(.).*1/
return re;
console.log("obcdo".test(s));
let suppose the specific set of chars is the vowel
(a, e, i, o, u)
in this case:
abcd ----> false
obcdo ----> true
ixyz ----> false
javascript regex
add a comment |
I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.
so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:
function regexVar()
var re = /(.).*1/
return re;
console.log("obcdo".test(s));
let suppose the specific set of chars is the vowel
(a, e, i, o, u)
in this case:
abcd ----> false
obcdo ----> true
ixyz ----> false
javascript regex
I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.
so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:
function regexVar()
var re = /(.).*1/
return re;
console.log("obcdo".test(s));
let suppose the specific set of chars is the vowel
(a, e, i, o, u)
in this case:
abcd ----> false
obcdo ----> true
ixyz ----> false
javascript regex
javascript regex
edited Mar 23 at 10:09
Ali Azim
asked Mar 23 at 9:52
Ali AzimAli Azim
13313
13313
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^
and $
to anchor the pattern to the start and end of the string, and repeat with 2,
rather than *
to make sure the whole string is at least 4 characters long:
/^([aeiou]).+1$/
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
add a comment |
You can use this pattern
/^([aeiou]).+1$/i
^
- Start of string([aeiou])
- Matchesa,e,i,o,u
any one of that. (group 1).+
- Match anything except new line.1
- Match group 1$
- End of string
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
1
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
1
@AliAzimi
flag is used for case insensitivity. so if you usei
flag, regex will treatuppercase
andlowercase
letters as same character. else it will treat them as two different characters
– Code Maniac
Mar 23 at 10:05
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%2f55312510%2fjavascript-match-a-string-which-start-with-a-specific-char-from-the-set-of-chars%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 need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^
and $
to anchor the pattern to the start and end of the string, and repeat with 2,
rather than *
to make sure the whole string is at least 4 characters long:
/^([aeiou]).+1$/
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
add a comment |
You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^
and $
to anchor the pattern to the start and end of the string, and repeat with 2,
rather than *
to make sure the whole string is at least 4 characters long:
/^([aeiou]).+1$/
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
add a comment |
You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^
and $
to anchor the pattern to the start and end of the string, and repeat with 2,
rather than *
to make sure the whole string is at least 4 characters long:
/^([aeiou]).+1$/
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^
and $
to anchor the pattern to the start and end of the string, and repeat with 2,
rather than *
to make sure the whole string is at least 4 characters long:
/^([aeiou]).+1$/
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
const re = /^([aeiou]).2,1$/
console.log(
re.test('abcd'),
re.test('obcdo'),
re.test('ixyz')
);
edited Mar 23 at 10:01
answered Mar 23 at 9:55
CertainPerformanceCertainPerformance
105k166797
105k166797
add a comment |
add a comment |
You can use this pattern
/^([aeiou]).+1$/i
^
- Start of string([aeiou])
- Matchesa,e,i,o,u
any one of that. (group 1).+
- Match anything except new line.1
- Match group 1$
- End of string
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
1
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
1
@AliAzimi
flag is used for case insensitivity. so if you usei
flag, regex will treatuppercase
andlowercase
letters as same character. else it will treat them as two different characters
– Code Maniac
Mar 23 at 10:05
add a comment |
You can use this pattern
/^([aeiou]).+1$/i
^
- Start of string([aeiou])
- Matchesa,e,i,o,u
any one of that. (group 1).+
- Match anything except new line.1
- Match group 1$
- End of string
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
1
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
1
@AliAzimi
flag is used for case insensitivity. so if you usei
flag, regex will treatuppercase
andlowercase
letters as same character. else it will treat them as two different characters
– Code Maniac
Mar 23 at 10:05
add a comment |
You can use this pattern
/^([aeiou]).+1$/i
^
- Start of string([aeiou])
- Matchesa,e,i,o,u
any one of that. (group 1).+
- Match anything except new line.1
- Match group 1$
- End of string
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
You can use this pattern
/^([aeiou]).+1$/i
^
- Start of string([aeiou])
- Matchesa,e,i,o,u
any one of that. (group 1).+
- Match anything except new line.1
- Match group 1$
- End of string
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
let startAndEnd = (str) =>
return /^([aeiou]).+1$/i.test(str)
console.log(startAndEnd(`ixyz`))
console.log(startAndEnd(`abcd`))
console.log(startAndEnd(`obcdo`))
answered Mar 23 at 9:57
Code ManiacCode Maniac
13.2k21034
13.2k21034
1
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
1
@AliAzimi
flag is used for case insensitivity. so if you usei
flag, regex will treatuppercase
andlowercase
letters as same character. else it will treat them as two different characters
– Code Maniac
Mar 23 at 10:05
add a comment |
1
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
1
@AliAzimi
flag is used for case insensitivity. so if you usei
flag, regex will treatuppercase
andlowercase
letters as same character. else it will treat them as two different characters
– Code Maniac
Mar 23 at 10:05
1
1
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
can you please explain what i is used for in this RegExp?
– Ali Azim
Mar 23 at 10:04
1
1
@AliAzim
i
flag is used for case insensitivity. so if you use i
flag, regex will treat uppercase
and lowercase
letters as same character. else it will treat them as two different characters– Code Maniac
Mar 23 at 10:05
@AliAzim
i
flag is used for case insensitivity. so if you use i
flag, regex will treat uppercase
and lowercase
letters as same character. else it will treat them as two different characters– Code Maniac
Mar 23 at 10:05
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%2f55312510%2fjavascript-match-a-string-which-start-with-a-specific-char-from-the-set-of-chars%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