I want to replace only part of the string matching the regular expression pattern. I found this answer , but I do not understand ... How to use substitution?
An example of what I want: save the first digit of the bullet, replace the others
/09/small_image/09x/> /09/thumbnail/1st: unknown digit2nd: "small_image"Third:unknown digit + "x"
/09/small_image/09x/
/09/thumbnail/
unknown digit
"small_image"
unknown digit + "x"
Here is what I still have:
var regexPattern = /\/\d\/small\_image\/\d*x/; var regexPattern = /\/\d\/(small\_image\/\d*x)$1/; ?? var result = regexPattern.test(str); if (result) { str = str.replace(regexPattern, 'thumbnail'); }
var input = "/09/small_image/09x/"; var output = input.replace(/(\/\d+\/)small_image\/\d*x/, "$1thumbnail"); console.log(output);
Explanation:
, , $1 - $1 . , (\/\d+\/) , , .
$1
(\/\d+\/)
( , .)
var regexPattern = /(\/\d+\/)small\_image\/\d*x/;
str = str.replace(regexPattern, '$1thumbnail');
, +. 09 - , , (\ḑ ). \d+, , , . /09/ , , regexp (... ), $1$2, $3...
+
09
\ḑ
\d+
/09/
(
)
$2
$3
Source: https://habr.com/ru/post/1657232/More articles:Why is the NPM module dependency always set to nested node_modules? - npmКонфигурация django apache с WSGIDaemonProcess не работает - pythonHow to sprout 1 turtle in a patch group - netlogoI get "Command / usr / bin / codesign failed" in Xcode when I try to create an application - xcodehttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1657231/applying-c11-move-semantics-to-bound-functions&usg=ALkJrhgWPo6IZRrzTErxIWcYUDYTy9V7lAHow to implement perfect forwarding to a non-generic type? - c ++https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1657234/how-to-update-sql-addins-to-work-in-ssms-2016&usg=ALkJrhgmYSaojxGDjGs3dwhKfc4X2PIwbgPercentage calculator does not display results - javaDoes the add-in for formatting poor people work for Management Studio 2012 in Management Studio 2016? - sql-serverКак найти значения ниже (или выше) среднего - pythonAll Articles