(?=) didn'work , i just change its position The 2019 Stack Overflow Developer Survey Results Are InHow to change an element's class with JavaScript?How to validate an email address using a regular expression?How do you access the matched groups in a JavaScript regular expression?jQuery Set Cursor Position in Text Areaevent.preventDefault() vs. return falseHow to match “anything up until this sequence of characters” in a regular expression?What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?Regular expression search replace in Sublime Text 2Is Safari on iOS 6 caching $.ajax results?Python string.replace regular expression
Why is Grand Jury testimony secret?
"What time...?" or "At what time...?" - what is more grammatically correct?
What is this 4-propeller plane?
It's possible to achieve negative score?
What does "sndry explns" mean in one of the Hitchhiker's guide books?
What tool would a Roman-age civilization have to grind silver and other metals into dust?
Could JWST stay at L2 "forever"?
"To split hairs" vs "To be pedantic"
A poker game description that does not feel gimmicky
In microwave frequencies, do you use a circulator when you need a (near) perfect diode?
Output the Arecibo Message
Why do UK politicians seemingly ignore opinion polls on Brexit?
Should I write numbers in words or as numerals when there are multiple next to each other?
Is it possible for the two major parties in the UK to form a coalition with each other instead of a much smaller party?
Can distinct morphisms between curves induce the same morphism on singular cohomology?
Is three citations per paragraph excessive for undergraduate research paper?
How was Skylab's orbit inclination chosen?
What does Linus Torvalds mean when he says that Git "never ever" tracks a file?
If the Wish spell is used to duplicate the effect of Simulacrum, are existing duplicates destroyed?
Monty Hall variation
Pristine Bit Checking
How to deal with fear of taking dependencies
Should I use my personal or workplace e-mail when registering to external websites for work purpose?
Inversion Puzzle
(?=) didn'work , i just change its position
The 2019 Stack Overflow Developer Survey Results Are InHow to change an element's class with JavaScript?How to validate an email address using a regular expression?How do you access the matched groups in a JavaScript regular expression?jQuery Set Cursor Position in Text Areaevent.preventDefault() vs. return falseHow to match “anything up until this sequence of characters” in a regular expression?What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?Regular expression search replace in Sublime Text 2Is Safari on iOS 6 caching $.ajax results?Python string.replace regular expression
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
My regular expression did not execute correctly.
I get different results when I change its position.
"bbbWindows" is not what I wanted. Why not 'bbb2222'?
'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb
'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows
javascript regex
add a comment |
My regular expression did not execute correctly.
I get different results when I change its position.
"bbbWindows" is not what I wanted. Why not 'bbb2222'?
'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb
'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows
javascript regex
?= is a positive lookahead, and it captures nothing.
– Xhua
Mar 22 at 3:04
add a comment |
My regular expression did not execute correctly.
I get different results when I change its position.
"bbbWindows" is not what I wanted. Why not 'bbb2222'?
'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb
'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows
javascript regex
My regular expression did not execute correctly.
I get different results when I change its position.
"bbbWindows" is not what I wanted. Why not 'bbb2222'?
'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb
'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows
javascript regex
javascript regex
asked Mar 22 at 2:53
Xu YoungXu Young
184
184
?= is a positive lookahead, and it captures nothing.
– Xhua
Mar 22 at 3:04
add a comment |
?= is a positive lookahead, and it captures nothing.
– Xhua
Mar 22 at 3:04
?= is a positive lookahead, and it captures nothing.
– Xhua
Mar 22 at 3:04
?= is a positive lookahead, and it captures nothing.
– Xhua
Mar 22 at 3:04
add a comment |
2 Answers
2
active
oldest
votes
Lookaheads ((?=...)
) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,
/Windows(?=bbb)/
Will match the substring Windows
only if the substring immediately following the s
also matches the pattern bbb
. On the other hand,
/(?=bbb)Windows/
Will match the substring Windows
only if the substring immediately following start position of the initial match also matches the pattern bbb
—which is impossible, no string will ever match that.
The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)
) and tweak your replacement string to insert this matched substring in the appropriate place ($N
). For example:
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
add a comment |
You should use positive lookbehind when the asserted pattern is behind the matching pattern:
'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
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%2f55292231%2fdidnwork-i-just-change-its-position%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
Lookaheads ((?=...)
) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,
/Windows(?=bbb)/
Will match the substring Windows
only if the substring immediately following the s
also matches the pattern bbb
. On the other hand,
/(?=bbb)Windows/
Will match the substring Windows
only if the substring immediately following start position of the initial match also matches the pattern bbb
—which is impossible, no string will ever match that.
The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)
) and tweak your replacement string to insert this matched substring in the appropriate place ($N
). For example:
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
add a comment |
Lookaheads ((?=...)
) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,
/Windows(?=bbb)/
Will match the substring Windows
only if the substring immediately following the s
also matches the pattern bbb
. On the other hand,
/(?=bbb)Windows/
Will match the substring Windows
only if the substring immediately following start position of the initial match also matches the pattern bbb
—which is impossible, no string will ever match that.
The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)
) and tweak your replacement string to insert this matched substring in the appropriate place ($N
). For example:
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
add a comment |
Lookaheads ((?=...)
) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,
/Windows(?=bbb)/
Will match the substring Windows
only if the substring immediately following the s
also matches the pattern bbb
. On the other hand,
/(?=bbb)Windows/
Will match the substring Windows
only if the substring immediately following start position of the initial match also matches the pattern bbb
—which is impossible, no string will ever match that.
The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)
) and tweak your replacement string to insert this matched substring in the appropriate place ($N
). For example:
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
Lookaheads ((?=...)
) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,
/Windows(?=bbb)/
Will match the substring Windows
only if the substring immediately following the s
also matches the pattern bbb
. On the other hand,
/(?=bbb)Windows/
Will match the substring Windows
only if the substring immediately following start position of the initial match also matches the pattern bbb
—which is impossible, no string will ever match that.
The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)
) and tweak your replacement string to insert this matched substring in the appropriate place ($N
). For example:
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222
edited Mar 22 at 3:38
answered Mar 22 at 3:27
p.s.w.gp.s.w.g
120k19216257
120k19216257
add a comment |
add a comment |
You should use positive lookbehind when the asserted pattern is behind the matching pattern:
'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
add a comment |
You should use positive lookbehind when the asserted pattern is behind the matching pattern:
'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
add a comment |
You should use positive lookbehind when the asserted pattern is behind the matching pattern:
'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')
You should use positive lookbehind when the asserted pattern is behind the matching pattern:
'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')
answered Mar 22 at 2:57
blhsingblhsing
43k41743
43k41743
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
add a comment |
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
Lookbehinds are not supported in JavaScript.
– p.s.w.g
Mar 22 at 3:17
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%2f55292231%2fdidnwork-i-just-change-its-position%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
?= is a positive lookahead, and it captures nothing.
– Xhua
Mar 22 at 3:04