Example string: [China] code - 001-02 - [code - 002-02 France] + [British] code - 003-02
Requirements: I need to replace the symbol "-", but "-" of the code - 001-02 cannot replace, after the replacement string should be like this:
[China] code - 001-02 [code - 002-02 France] [British] code - 003-02
Thank you thank you very much!
CodePudding user response:
Replace related to regular
CodePudding user response:
1/f, reference for emotion unavoidably lonely tears don't reply: replace have anything to do with regular Would you? Regex. Replace (string, "regular", "") CodePudding user response:
(? <=\]). *? (?=\ [) CodePudding user response:
refer to the third floor and foliage quiet reply: (? <=\]). *? (?=\ [) Thank you very much! Sorry, I describe the problem is not clear, then add: Actually needs a bit more complicated, such as string could be like this: [China] code - 001-02. [& amp; 01] - [code - 002-02 France] [& amp; 02] + [British] code - 003-02. [& amp; 03] After processing: [China] code - 001-02. [& amp; 01] [French] code - 002-02. [& amp; 02] [British] code - 003-02. [& amp; 03] So I need to find the specific characters. (? <=\]). *? (?=\ [) cannot meet this expression, CodePudding user response:
Don't know why we can't match: if with a plus sign or other you can, can't it happened that a minus sign (? <=\]) \ - *? (?=\ [) CodePudding user response:
Is that right CodePudding user response:
Oneself fumble, (? <=\]) - *? (?=\ [) can, originally a minus sign is not a metacharacter, also solved the problem, but still not perfect, If the character is like this: [China] code - 001-02. [& amp; 01] - aa [code - 002-02 France] [& amp; 02] + [British] code - 003-02. [& amp; 03] Can not match, CodePudding user response:
The reference from the 6th floor the foliage silent response: is that right Thank you very much, just want to continue to ask, see the 7th floor CodePudding user response:
let str123="[China] code - 001-02 - [code - 002-02 France] + [British] code - 003-02" Str123. Replace (/\] + [-] \ [/g, "] [") Look in the console to run CodePudding user response:
references 9 f chinaskysun response: let str123="[China] code - 001-02 - [code - 002-02 France] + [British] code - 003-02" Str123. Replace (/\] + [-] \ [/g, "] [") Look in the console running THX! This for string [China] code - 001-02. [& amp; 01] [color=# FF00FF] - aa [code - 002-02 France] [& amp; 02] + [British] code - 003-02. [& amp; 03] [/color] no ah, pay attention to the middle - aa