Home > Web Front-end > JS Tutorial > body text

js date string interception and split into a single specific date (2009-12-30 13:28:29)_time and date

WBOY
Release: 2016-05-16 18:39:11
Original
1765 people have browsed it

[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

The following is replaced by array regular expression Implemented code

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]

"hand hand hand" think Transform to "hand.gif hand.gif hand.gif"
Start with
str=str.replace("hand","hand.gif");
Output: hand.gif hand hand
replaced only once. . . :(
I thought of using regular expressions, because replace can be replaced with regular expressions.

Quote
Returns a copy of the string after text replacement according to the regular expression.

stringObj .replace(rgExp, replaceText)


So write
str = str.replace(/hand/,"hand.gif")
to replace all. Add g,
str = str.replace(/hand/g, "hand.gif")
Still not working: (

Refer to JavaScript's replace method and regular expression to explain this After reading this article, I finally realized that it turns out that the stuff in () needs to be enclosed in (). The correct way to write it is as follows:
str = "hand hand hand";
str=str.replace((). /(hand)/g,"hand.gif");
document.write(str);
Correct output: hand.gif hand.gif hand.gif.

JS regular expression. One way to write it is to use RegExp:
such as str=str.replace(/(hand)/g,"hand.gif");
is equivalent to:
reg = new RegExp("(hand)" ,"g");
str = str.replace(reg,'hand.gif');
This method is more suitable when reg needs to be generated dynamically.

Expand it:
str = "hand'( hand'( hand'(";
str=str.replace(/(hand'()/g,"hand.gif");
document.write(str);

str = 'hand'( hand'( hand'(';
str=str.replace(/(hand'()/g,"hand.gif"); document. write(str);
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template