web.js.String and regular expression operation example tutorial
This article mainly introduces relevant information about web.js. string and regular expression operations. Friends in need can refer to
1.substring
var str='abcdef'; alert(str.substring(2, 5)); //cde不包括结束位置 alert(str.substring(1));//bcdef1
2.split
var str='a*b*cd*ef'; alert(str.split('*'));//分割字符1
3.search
var str='acef'; alert(str.search(‘a'));//0查找字符位置 alert(str.search(‘f'));//3 alert(str.search(‘ce'));//1 alert(str.search(‘o'));//-1匹配失败则-1
regular
var re=new RegExp('b', 'i'); //i不考虑大小写 //或者var re=/b/i; var str='abcdef';//将b换成B同样的结果,如果去掉i就不行了 alert(str.search(re));
1.match
var str='asdf 34 656 cvs33'; var re=/\d/g; alert(str.match(re));//3,4,6,5,6,3,3match 获取匹配的项目1 var str='asdf 34 656 cvs33'; var re=/\d+/g;//全局匹配:g——global,+表示一次或者多次 alert(str.match(re));//34,656,33
2.replace
var str='asdf 34 656 cvs33'; var re=/\d+/g; var re2=/\d/g; alert(str.replace(re,'*'));//asdf * * cvs*; alert(str.replace(re2,'*'));//asdf ** *** cvs**1
Remove sensitive words
var str='河南 一村民 开封 哈哈' var re=/河南|开封/g;//去掉敏感词河南或开封 var re1=/河南|开封/; alert(str.replace(re,'*')); alert(str.replace(re1,'*'))//没有去掉开封,自己试试结果1
3 .[] Any character, range
[abc]
Example: o[usb]t——obt, ost, out
[a-z ], [0-9]
Example: id[0-9]——id0, id5
[^a](exclude everything except a)
Example: o[^0-9]t——oat, o?t, o t
combination
[a-z0-9A-Z]
【Related Recommendations】
1. Special Recommendation:"php Programmer Toolbox" V0.1 version download
2. Free js online video tutorial
##3.php.cn Dugu Jiujian (3) - JavaScript video tutorial
The above is the detailed content of web.js.String and regular expression operation example tutorial. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP regular expression verification: Number format detection When writing PHP programs, it is often necessary to verify the data entered by the user. One of the common verifications is to check whether the data conforms to the specified number format. In PHP, you can use regular expressions to achieve this kind of validation. This article will introduce how to use PHP regular expressions to verify number formats and provide specific code examples. First, let’s look at common number format validation requirements: Integers: only contain numbers 0-9, can start with a plus or minus sign, and do not contain decimal points. floating point

To validate email addresses in Golang using regular expressions, follow these steps: Use regexp.MustCompile to create a regular expression pattern that matches valid email address formats. Use the MatchString function to check whether a string matches a pattern. This pattern covers most valid email address formats, including: Local usernames can contain letters, numbers, and special characters: !.#$%&'*+/=?^_{|}~-`Domain names must contain at least One letter, followed by letters, numbers, or hyphens. The top-level domain (TLD) cannot be longer than 63 characters.

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.

Go language is a powerful and flexible programming language that provides rich string processing functions, including string interception. In the Go language, we can use slices to intercept strings. Next, we will introduce in detail how to intercept strings in Go language, with specific code examples. 1. Use slicing to intercept a string. In the Go language, you can use slicing expressions to intercept a part of a string. The syntax of slice expression is as follows: slice:=str[start:end]where, s

PHP String Operation: A Practical Method to Effectively Remove Spaces In PHP development, you often encounter situations where you need to remove spaces from a string. Removing spaces can make the string cleaner and facilitate subsequent data processing and display. This article will introduce several effective and practical methods for removing spaces, and attach specific code examples. Method 1: Use the PHP built-in function trim(). The PHP built-in function trim() can remove spaces at both ends of the string (including spaces, tabs, newlines, etc.). It is very convenient and easy to use.

The method of using regular expressions to verify passwords in Go is as follows: Define a regular expression pattern that meets the minimum password requirements: at least 8 characters, including lowercase letters, uppercase letters, numbers, and special characters. Compile regular expression patterns using the MustCompile function from the regexp package. Use the MatchString method to test whether the input string matches a regular expression pattern.
