B2BÍøÂçÈí¼þ

 ÕÒ»ØÃÜÂë
 Á¢¼´×¢²á ÉóºËÍøÕ¾ºÅ:QQ:896757558
ËÑË÷
²é¿´: 15|»Ø¸´: 0
´òÓ¡ ÉÏÒ»Ö÷Ìâ ÏÂÒ»Ö÷Ìâ

AIWROKÈí¼þ³£¼ûÕýÔò·½·¨¼¯ºÏС½á

[¸´ÖÆÁ´½Ó]

832

Ö÷Ìâ

837

Ìû×Ó

6604

»ý·Ö

abc

Rank: 9Rank: 9Rank: 9

»ý·Ö
6604
Ìøתµ½Ö¸¶¨Â¥²ã
Â¥Ö÷
//ÊÊÓñ¾ÎĵµES5ϵͳ°²×¿ JavaScriptÒýÇæRhino
const ×Ö·û = {
/**
* Æ¥Åä²éÕÒ×Ö·û´®ÖеÄÄÚÈÝ
* @param {string} str ÐèÒª²éÕÒµÄ×Ö·û´®
* @param {string|RegExp} searchvalue ÐèÒª²éÕÒµÄ×Ö·û´®»òÕýÔò±í´ïʽ
* @returns {Array|null} ³É¹¦:·µ»Ø°üº¬Æ¥Åä½á¹ûµÄÊý×é,ʧ°Ü:·µ»Ønull
* @example
* // ʾÀý1£º²éÕÒ×Ö·û´®
* var str = "How are you doing you today?";
* var fgh = ×Ö·û.Æ¥Åä²éÕÒ(str, 'you');
* printl(fgh); // Êä³ö: ["you", "you"]
*
* // ʾÀý2£ºÊ¹ÓÃÕýÔò±í´ïʽ²éÕÒ
* var str = "How are you doing you today?";
* var fgh = ×Ö·û.Æ¥Åä²éÕÒ(str, /you/gi);
* printl(fgh); // Êä³ö: ["you", "you"]
*/
Æ¥Åä²éÕÒ: function(str, searchvalue) {
try {
// ²ÎÊýÑéÖ¤
if (typeof str === "undefined" || str === null) {
console.error("[×Ö·û.Æ¥Åä²éÕÒ] ´íÎó£ºstr²ÎÊý䶨Òå»òΪnull");
return null;
}
if (typeof searchvalue === "undefined" || searchvalue === null) {
console.error("[×Ö·û.Æ¥Åä²éÕÒ] ´íÎó£ºsearchvalue²ÎÊý䶨Òå»òΪnull");
return null;
}

// ת»»Îª×Ö·û´®
str = String(str);

// Èç¹ûsearchvalueÊÇ×Ö·û´®£¬×ª»»ÎªÈ«¾ÖÕýÔò±í´ïʽ
if (typeof searchvalue === 'string') {
searchvalue = new RegExp(searchvalue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
}
// Èç¹ûÊÇÕýÔò±í´ïʽµ«Ã»ÓÐÈ«¾Ö±êÖ¾£¬Ìí¼ÓÈ«¾Ö±êÖ¾
else if (searchvalue instanceof RegExp && !searchvalue.global) {
searchvalue = new RegExp(searchvalue.source, searchvalue.flags + 'g');
}

// Ö´ÐÐÆ¥Åä²éÕÒ²Ù×÷
let matches = str.match(searchvalue);

// Èç¹ûûÓÐÕÒµ½Æ¥ÅäÏ·µ»Ønull
if (!matches || matches.length === 0) {
return null;
}

return matches;
} catch (error) {
console.error(`[×Ö·û.Æ¥Åä²éÕÒ] ´íÎó£º${error}`);
return null;
}
},

/**
* Æ¥ÅäË÷Òý£¬²éÕÒ×Ö·û´®ÖÐÄÚÈݵÄλÖÃ
* @param {string} str ÐèÒª²éÕÒµÄ×Ö·û´®
* @param {string|RegExp} searchvalue ÐèÒª²éÕÒµÄ×Ö·û´®»òÕýÔò±í´ïʽ
* @returns {Array|null} ³É¹¦:·µ»Ø°üº¬Æ¥ÅäλÖÃË÷ÒýµÄÊý×é,ʧ°Ü:·µ»Ønull
* @example
* // ʾÀý1£º²éÕÒ×Ö·û´®Î»ÖÃ
* var str = "How are you doing you today?";
* var fgh = ×Ö·û.Æ¥ÅäË÷Òý(str, 'you');
* printl(fgh); // Êä³ö: [8, 19]
*
* // ʾÀý2£ºÊ¹ÓÃÕýÔò±í´ïʽ²éÕÒλÖÃ
* var str = "How are you doing you today?";
* var fgh = ×Ö·û.Æ¥ÅäË÷Òý(str, /you/gi);
* printl(fgh); // Êä³ö: [8, 19]
*/
Æ¥ÅäË÷Òý: function(str, searchvalue) {
try {
// ²ÎÊýÑéÖ¤
if (typeof str === "undefined" || str === null) {
console.error("[×Ö·û.Æ¥ÅäË÷Òý] ´íÎó£ºstr²ÎÊý䶨Òå»òΪnull");
return null;
}
if (typeof searchvalue === "undefined" || searchvalue === null) {
console.error("[×Ö·û.Æ¥ÅäË÷Òý] ´íÎó£ºsearchvalue²ÎÊý䶨Òå»òΪnull");
return null;
}

// ת»»Îª×Ö·û´®
str = String(str);

// ×¼±¸ÕýÔò±í´ïʽ
let regex;
if (typeof searchvalue === 'string') {
// Èç¹ûÊÇ×Ö·û´®£¬×ª»»ÎªÕýÔò±í´ïʽ²¢×ªÒåÌØÊâ×Ö·û
regex = new RegExp(searchvalue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
} else if (searchvalue instanceof RegExp) {
// Èç¹ûÒѾ­ÊÇÕýÔò±í´ïʽ£¬È·±£ÓÐÈ«¾Ö±êÖ¾
if (!searchvalue.global) {
regex = new RegExp(searchvalue.source, searchvalue.flags + 'g');
} else {
regex = searchvalue;
}
} else {
console.error("[×Ö·û.Æ¥ÅäË÷Òý] ´íÎó£ºsearchvalueÀàÐͲ»ÕýÈ·");
return null;
}

// ²éÕÒËùÓÐÆ¥ÅäµÄË÷Òý
let indices = [];
let match;

// ÖØÖÃlastIndexÒÔÈ·±£´ÓÍ·¿ªÊ¼ËÑË÷
regex.lastIndex = 0;

while ((match = regex.exec(str)) !== null) {
indices.push(match.index);

// ·ÀÖ¹Á㳤¶ÈÆ¥Åäµ¼ÖµÄÎÞÏÞÑ­»·
if (match.index === regex.lastIndex) {
regex.lastIndex++;
}
}

// Èç¹ûûÓÐÕÒµ½Æ¥ÅäÏ·µ»Ønull
if (indices.length === 0) {
return null;
}

return indices;
} catch (error) {
console.error(`[×Ö·û.Æ¥ÅäË÷Òý] ´íÎó£º${error}`);
return null;
}
}
};

// ʾÀý1£ºÊ¹ÓÃ×Ö·û´®²éÕÒ
var str = "How are you doing you today?";
var fgh = ×Ö·û.Æ¥Åä²éÕÒ(str, 'you');
printl(fgh); // Êä³ö: ["you", "you"]

// ʾÀý2£ºÊ¹ÓÃÕýÔò±í´ïʽ²éÕÒ
var str = "How are you doing you today?";
var fgh = ×Ö·û.Æ¥Åä²éÕÒ(str, /you/gi);
printl(fgh); // Êä³ö: ["you", "you"]

// ʾÀý3£ºÊ¹ÓÃ×Ö·û´®²éÕÒË÷Òý
var str = "How are you doing you today?";
var fgh = ×Ö·û.Æ¥ÅäË÷Òý(str, 'you');
printl(fgh); // Êä³ö: [8, 19]

// ʾÀý4£ºÊ¹ÓÃÕýÔò±í´ïʽ²éÕÒË÷Òý
var str = "How are you doing you today?";
var fgh = ×Ö·û.Æ¥ÅäË÷Òý(str, /you/gi);
printl(fgh); // Êä³ö: [8, 19]

1. ÕûÌå½á¹¹

ÕâÊÇÒ»¸öÃûΪ×Ö·ûµÄ¶ÔÏ󣬰üº¬Á½¸öÖ÷Òª·½·¨£º

  • Æ¥Åä²éÕÒ: ÓÃÓÚ²éÕÒ×Ö·û´®ÖеÄÆ¥ÅäÄÚÈÝ
  • Æ¥ÅäË÷Òý: ÓÃÓÚ²éÕÒÆ¥ÅäÄÚÈÝÔÚ×Ö·û´®ÖеÄλÖÃ

2. Æ¥Åä²éÕÒ·½·¨ (×Ö·û.Æ¥Åä²éÕÒ)


×Ö·û.Æ¥Åä²éÕÒ(str, searchvalue)

²ÎÊý˵Ã÷£º

  • str: ÒªËÑË÷µÄÄ¿±ê×Ö·û´®
  • searchvalue: ËÑË÷Ìõ¼þ£¬¿ÉÒÔÊÇ×Ö·û´®»òÕýÔò±í´ïʽ

¹¦ÄÜÌص㣺

  1. ²ÎÊýÑéÖ¤£º

if (typeof str === "undefined" || str === null) {
    console.error("[×Ö·û.Æ¥Åä²éÕÒ] ´íÎó£ºstr²ÎÊý䶨Òå»òΪnull");
    return null;
}
  • ¼ì²é²ÎÊýÊÇ·ñΪ¿Õ»ò䶨Òå
  • ³ö´íʱ·µ»Ønull²¢´òÓ¡´íÎóÐÅÏ¢
  1. ×Ö·û´®´¦Àí£º

str = String(str);
  • ½«ÊäÈëת»»Îª×Ö·û´®£¬È·±£¿ÉÒÔ½øÐÐÆ¥Åä²Ù×÷
  1. ËÑË÷Ìõ¼þ´¦Àí£º

if (typeof searchvalue === 'string') {
    searchvalue = new RegExp(searchvalue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
}
  • Èç¹ûÊÇ×Ö·û´®£¬×ª»»ÎªÕýÔò±í´ïʽ²¢×ªÒåÌØÊâ×Ö·û
  • Èç¹ûÊÇÕýÔò±í´ïʽ£¬È·±£ÓÐÈ«¾Ö±êÖ¾
  1. Ö´ÐÐÆ¥Å䣺

let matches = str.match(searchvalue);
  • ʹÓÃJavaScriptµÄmatch·½·¨½øÐÐÆ¥Åä
  • ·µ»ØËùÓÐÆ¥ÅäÏîµÄÊý×é

3. Æ¥ÅäË÷Òý·½·¨ (×Ö·û.Æ¥ÅäË÷Òý)


×Ö·û.Æ¥ÅäË÷Òý(str, searchvalue)

²ÎÊý˵Ã÷£º

  • ÓëÆ¥Åä²éÕÒ·½·¨Ïàͬ£¬µ«·µ»ØÆ¥ÅäλÖöø²»ÊÇÆ¥ÅäÄÚÈÝ

¹¦ÄÜÌص㣺

  1. ²ÎÊýÑéÖ¤£ºÓëÆ¥Åä²éÕÒÏàͬ
  2. ÕýÔò±í´ïʽ´¦Àí£º

let regex;
if (typeof searchvalue === 'string') {
    regex = new RegExp(searchvalue.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
}
  • ½«ËÑË÷Ìõ¼þͳһת»»ÎªÕýÔò±í´ïʽ
  • ´¦ÀíÌØÊâ×Ö·ûºÍÈ«¾Ö±êÖ¾
  1. ²éÕÒλÖãº

while ((match = regex.exec(str)) !== null) {
    indices.push(match.index);
}
  • ʹÓÃexec·½·¨Ñ­»·²éÕÒËùÓÐÆ¥Åä
  • ¼Ç¼ÿ¸öÆ¥ÅäµÄλÖã¨Ë÷Òý£©
  1. ·ÀÖ¹ËÀÑ­»·£º

if (match.index === regex.lastIndex) {
    regex.lastIndex++;
}
  • ´¦ÀíÁ㳤¶ÈÆ¥ÅäµÄÌØÊâÇé¿ö
  • È·±£ËÑË÷Ö¸ÕëÇ°½ø

4. ´íÎó´¦Àí

Á½¸ö·½·¨¶¼°üº¬ÍêÕûµÄ´íÎó´¦Àí»úÖÆ£º


try {
    // ·½·¨Ö÷Ìå
} catch (error) {
    console.error(`[×Ö·û.xxx] ´íÎó£º${error}`);
    return null;
}
  • ʹÓÃtry-catch²¶»ñËùÓпÉÄܵĴíÎó
  • ³ö´íʱ·µ»Ønull²¢´òÓ¡Ïêϸ´íÎóÐÅÏ¢

5. ʹÓÃʾÀý

´úÂë°üº¬ËĸöÍêÕûµÄʾÀý£º


// ʾÀý1£ºÊ¹ÓÃ×Ö·û´®²éÕÒÄÚÈÝ
var str = "How are you doing you today?";
var fgh = ×Ö·û.Æ¥Åä²éÕÒ(str, 'you');
printl(fgh);  // Êä³ö: ["you", "you"]

// ʾÀý2£ºÊ¹ÓÃÕýÔò±í´ïʽ²éÕÒÄÚÈÝ
var fgh = ×Ö·û.Æ¥Åä²éÕÒ(str, /you/gi);
printl(fgh);  // Êä³ö: ["you", "you"]

// ʾÀý3£ºÊ¹ÓÃ×Ö·û´®²éÕÒλÖÃ
var fgh = ×Ö·û.Æ¥ÅäË÷Òý(str, 'you');
printl(fgh);  // Êä³ö: [8, 19]

// ʾÀý4£ºÊ¹ÓÃÕýÔò±í´ïʽ²éÕÒλÖÃ
var fgh = ×Ö·û.Æ¥ÅäË÷Òý(str, /you/gi);
printl(fgh);  // Êä³ö: [8, 19]

6. ´úÂëÌصã

  1. ½¡×³ÐÔ£º
  • ÍêÕûµÄ²ÎÊýÑéÖ¤
  • È«ÃæµÄ´íÎó´¦Àí
  • ÌØÊâÇé¿öµÄ´¦Àí£¨ÈçÁ㳤¶ÈÆ¥Å䣩
  1. Áé»îÐÔ£º
  • Ö§³Ö×Ö·û´®ºÍÕýÔò±í´ïʽÁ½ÖÖËÑË÷·½Ê½
  • ×Ô¶¯´¦ÀíÕýÔò±í´ïʽ±êÖ¾
  • תÒåÌØÊâ×Ö·û
  1. ¿Éά»¤ÐÔ£º
  • ÇåÎúµÄ´úÂë½á¹¹
  • ÏêϸµÄ×¢ÊͺÍÎĵµ
  • ͳһµÄ´íÎó´¦Àí·½Ê½
  1. ʹÓñãÀû£º
  • ¼òµ¥Ö±¹ÛµÄAPI
  • ÍêÕûµÄʹÓÃʾÀý
  • ÇåÎúµÄ·µ»ØÖµÔ¼¶¨

Õâ¶Î´úÂëÌṩÁËÒ»¸öÍêÕûµÄ×Ö·û´®²éÕÒ½â¾ö·½°¸£¬¼È¿ÉÒÔ»ñÈ¡Æ¥ÅäµÄÄÚÈÝ£¬Ò²¿ÉÒÔ»ñÈ¡Æ¥ÅäµÄλÖã¬ÊÊÓÃÓÚ¸÷ÖÖ×Ö·û´®´¦Àí³¡¾°¡£

AIWROKÈí¼þ³£¼ûÕýÔò·½·¨¼¯ºÏС½á B2BÍøÂçÈí¼þ

AIWROKÈí¼þ³£¼ûÕýÔò·½·¨¼¯ºÏС½á B2BÍøÂçÈí¼þ   AIWROKÈí¼þ³£¼ûÕýÔò·½·¨¼¯ºÏС½á B2BÍøÂçÈí¼þ

»Ø¸´

ʹÓõÀ¾ß ¾Ù±¨

±¾°æ»ý·Ö¹æÔò

¹Ø±Õ

QQ|»ÓªÏúÈí¼þ×ÛºÏÌÖÂÛ|»ÓªÏúÈí¼þÓÐÎʱشð|»ÓªÏúÈí¼þ½Ì³ÌרÇø|»ÓªÏúÈí¼þPOST½Å±¾·ÖÏí|»ÓªÏúÈí¼þÆÕͨ½Å±¾·ÖÏí|»ÓªÏúÈí¼þÈí¼þ×ÊѶ|»ÓªÏúÈí¼þ¾«Æ·Èí¼þ|»ÓªÏúÈí¼þ¸üй«¸æ|ÓªÏúÈí¼þ|B2BÈí¼þ|B2BÍøÂçÈí¼þ ( ¾©ICP±¸09078825ºÅ )±¾ÍøÕ¾¿ª·¢µÄÓªÏúÈí¼þÊÇÒ»¿îеÄÍøÂçÓªÏúÈí¼þ£¬Õâ¿îÓªÏú¿ÉÒÔÈ¥ÍøÕ¾Èí¼þ£¬²©¿ÍÈí¼þ£¬B2BÈí¼þ£¬·ÖÀàÐÅÏ¢Íø·¢Ìù£¬¿ÉÒÔÇÀɳ·¢£¬¿ÉÒÔµ½°Ù¶ÈÎÄ¿âÉÏ´«WORDÎĵµ£¬¿ÉÒÔµ½Ò»Ð©ÊÇÏà²áÍøÕ¾×Ô¶¯ÉÏ´«Í¼Æ¬£¬Õâ¸ö×Ô¶¯·¢ÌûÈí¼þ×Ô´øÔÆÖ©Ö룬¼Ó¿ìÊÕ¼£¬ÓÐ6ÖÖ¶Ô½Ó´òÂë½Ó¿Ú£¬·½±ã£¬Ð§Âʸߣ¬Ëٶȿ죬¶øÇÒ¶ÔÍ϶¯µÄÑéÖ¤ÂëÈ«ÍøµÚÒ»¼Ò¶À¼ÒÖ§³Ö£¬È«²¿Ô­´´¼¼Êõ£¬¶À¼ÒÑз¢£¬Õý°æÔ­´´´ø°æȨÈí¼þ¡£Ñ¡ÔñÍòÄÜÓªÏúÈí¼þ£¬¾ÍÑ¡ÔñÁËÒ»ÖÖ׬ǮµÄЧÂÊ£¬´ÓûÓб»³¬Ô½¹ý£¬Ò»Ö±ÔÚŬÁ¦Ñз¢Ð¼¼Êõ¡£·Å·ÉÃÎÏ룬½â·ÅË«ÊÖ£¬À´µã´´Ò⣬³É¾ÍÄãµÄÃÎÏ룬¾ÍÔÚÍòÄÜÓªÏúÈí¼þ¿ªÊ¼

map2

GMT+8, 2025-4-3 10:17 , Processed in 0.235453 second(s), 36 queries .

¿ìËٻظ´ ·µ»Ø¶¥²¿ ·µ»ØÁбí