Home Web Front-end JS Tutorial Get the longest continuous substring through regularity

Get the longest continuous substring through regularity

Apr 16, 2018 pm 04:51 PM
longest continuous

给大家带来通过正则取得最长连续子串,通过正则取得最长连续子串的注意事项有哪些,下面就是实战案例,一起来看一下。

function maxLenStr(str){
  var len = 0, max_len = 0;
  var reg = new RegExp("(.)\\1{1,}","g");
  var res = reg.exec(str);
  while(res != null){
    len = res[0].length;
    if(max_len < len){
      max_len = len;
    }
    res = reg.exec(str)
  }
  return max_len;
}
Copy after login

js使用正则查找子串

var str = '#param1#abcdef#param2#hjklllj#param3#7878'
var count = str.match(/param\d*/g)
console.log(count) // ["param1", "param2", "param3"]
Copy after login

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:



The above is the detailed content of Get the longest continuous substring through regularity. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1657
14
PHP Tutorial
1257
29
C# Tutorial
1230
24
How to check the time when Xiaohongshu released a video? What is the longest time it takes to post a video? How to check the time when Xiaohongshu released a video? What is the longest time it takes to post a video? Mar 21, 2024 pm 04:26 PM

As a lifestyle sharing platform, Xiaohongshu is where more and more users choose to publish their own video content and share their daily life with other users. Many users may encounter a problem when posting videos: How to check the time when they or others posted videos? 1. How to check the time when Xiaohongshu released a video? 1. Check the time when you posted the video. To check the time when you posted the video, you must first open the Xiaohongshu app and log in to your personal account. At the bottom of the personal homepage interface, there will be an option marked &quot;Creation&quot;. After clicking to enter, you will see a column called &quot;Video&quot;. Here you can browse a list of all published videos and easily check when they were published. There is a &quot;View Details&quot; button in the upper right corner of each video. After clicking

Longest non-increasing subsequence in a binary string Longest non-increasing subsequence in a binary string Sep 07, 2023 pm 11:13 PM

In this problem, we need to find the longest non-increasing subsequence of a given string. Non-increasing means that the characters are either the same or in descending order. Since binary strings only contain "0" and "1", the resulting string should either start with "1" and end with "0", or start and end with "0" or "1". To solve this problem, we will count the prefix "1" and suffix "0" at each position of the string and find the maximum sum of prefix "1" and suffix "0". Problem Statement - We are given a binary string str. We need to find the longest non-increasing subsequence from the given string. Example Input–str="010100"Output–4 illustrates the longest non-recursive

Do I need to keep the mouse driver software open? Do I need to keep the mouse driver software open? Feb 19, 2024 pm 10:40 PM

Should the mouse driver always be turned on? The mouse is one of the indispensable input devices in our daily use of computers. In addition to the quality of the hardware itself, the mouse driver is also key to the normal functioning of the mouse. However, many people have some questions about the role and necessity of the mouse driver, especially whether the mouse driver needs to be turned on all the time. First, we need to understand what the mouse driver does. A mouse driver is a software program whose main responsibility is to communicate with the operating system in order to identify and control mouse movements, clicks, and scrolling. The mouse driver can

Write a program in C/C++ to count the number of binary strings without consecutive 1's? Write a program in C/C++ to count the number of binary strings without consecutive 1's? Aug 25, 2023 pm 10:05 PM

Here we will see an interesting problem. Suppose a value n is given. We must find all strings of length n in which there are no consecutive 1's. If n=2, the numbers are {00,01,10}, so the output is 3. We can use dynamic programming to solve it. Suppose we have a table 'a' and 'b'. where arr[i] stores the number of binary strings of length i that have no consecutive 1's and terminate with 0. Similarly, b is the same but ends in 1. We can add 0 or 1 if the last one is 0, but only add 0 if the last one is 1. Let's look at the algorithm to get this idea. Algorithm noConsecutiveOnes(n)-Begin&am

C++ program: find the longest subsequence of numbers with the same left and right rotation C++ program: find the longest subsequence of numbers with the same left and right rotation Aug 30, 2023 pm 01:33 PM

In this problem, we need to find the maximum length of a subsequence with the same left and right rotation. Left rotation means moving all the characters in the string to the left, and moving the first character at the end. Right rotation means moving all string characters to the right and moving the last character to the beginning. Problem Statement – ​​We are given a string str containing numbers and need to find the subsequence of maximum length with the same rotation for left and right. Example input - str="323232", output -6 Explanation - The longest subsequence with the same left and right rotation is "323232". Rotate it left to ‘232323’ and rotate it right to ‘232323’. Input -str=‘00010100’ Output – 6 Description – The longest subsequence with the same left and right rotation is “00

Checks whether there are T consecutive blocks of 0's in the given binary matrix Checks whether there are T consecutive blocks of 0's in the given binary matrix Aug 26, 2023 pm 02:41 PM

Introduction Binary matrices are widely used in computer science and various fields to represent data efficiently or solve complex problems. In some cases, it becomes important to identify whether a given binary matrix contains consecutive blocks of zeros. In this article, we will explore an elegant solution using C++ code that allows us to detect the presence of T consecutive blocks of zeros in a given binary matrix. This approach is both intuitive and efficient, making it suitable for practical implementation. Check if there are T consecutive blocks of zeros Given a 2D binary matrix of dimension NxM and an integer T, we need to determine whether there are T consecutive blocks of zeros in the matrix (where "contiguous" means adjacent horizontally or vertically) . To achieve this, let's break down the process step by step using logical and algorithmic methods. lose

What should I do if I can't press the keyboard twice in succession in Windows 10? What should I do if I can't press the keyboard twice in succession in Windows 10? Dec 24, 2023 pm 03:20 PM

When using our win10 system, many users will encounter the situation that we cannot press the same key continuously for text input, etc. If we press it continuously, it will have no effect. What should we do about this problem? To solve it, come and take a look at the detailed tutorial ~ What to do if win10 cannot press the keyboard twice in a row: 1. Open it. 2. Then find - in settings. 3. Then turn off the options therein. Related articles: What to do if the win10 keyboard is not responding at all >>> Detailed tutorial on how to restore the win10 keyboard to shortcut keys >>>

Given a string, find the sum of consecutive numbers in it Given a string, find the sum of consecutive numbers in it Aug 28, 2023 am 09:17 AM

Problem StatementWehavegivenstringstrcontainingthenumericandalphabeticalcharacters.Weneedtofindthesumofallnumbersrepresentedbyacontinuoussequenceofdigitsavailableinthegivenstring.Example

See all articles