Table of Contents
回复内容:
Home Backend Development PHP Tutorial javascript - 正则表达式,如何分组?地址和标题分一组

javascript - 正则表达式,如何分组?地址和标题分一组

Jun 06, 2016 pm 08:14 PM
java javascript php python

<code>http://s.click.taobao.com/t?e=m%3D2%26s%3DC1Wj%2FDUvnQAcQipKwQzePOeEDrYVVa64REOHN%2B0iJT23bLqV5UHdqcvC2rKjuw6htYQMu9Tydq0qC%2FWAES3KjEVAR5FF1Zuf0M83nhvB7wsgfuBp9F3RPL6hW3GYyufa0nk1uZWo%2BVgFCjfdoeI9bCSQFfUF8UG8x1IYFu75azTnWUvVnK10NV9FS%2FIENZ7iyNYJBoTNJ8s%3D
创意男女雨伞长柄伞晴雨伞双人伞超大拍下19.8元包邮
http://s.click.taobao.com/t?e=m%3D2%26s%3D7hgtkzLk%2FnkcQipKwQzePOeEDrYVVa64qu1K02Mshg63bLqV5UHdqcvC2rKjuw6h0e71iVTN2RwqC%2FWAES3KjEVAR5FF1Zuf0M83nhvB7wsgfuBp9F3RPP0sHo1DWd7dVEdXKgUyOXuT1UqJ0PWIzMZOr18RYav6TWOYZ4V%2FN1d%2FC3KL%2B7ueeV1VbYMvpJWxTM78ni%2FxOXSiZ%2BQMlGz6FQ%3D%3D
佳诺仰卧板仰卧起坐健身器材仅78元起包邮
</code>
Copy after login
Copy after login

上面的文本,如何变成2组,每组包括地址和标题?
我用下面的正则匹配出了5组搞了半天没搞出来

javascript - 正则表达式,如何分组?地址和标题分一组

回复内容:

<code>http://s.click.taobao.com/t?e=m%3D2%26s%3DC1Wj%2FDUvnQAcQipKwQzePOeEDrYVVa64REOHN%2B0iJT23bLqV5UHdqcvC2rKjuw6htYQMu9Tydq0qC%2FWAES3KjEVAR5FF1Zuf0M83nhvB7wsgfuBp9F3RPL6hW3GYyufa0nk1uZWo%2BVgFCjfdoeI9bCSQFfUF8UG8x1IYFu75azTnWUvVnK10NV9FS%2FIENZ7iyNYJBoTNJ8s%3D
创意男女雨伞长柄伞晴雨伞双人伞超大拍下19.8元包邮
http://s.click.taobao.com/t?e=m%3D2%26s%3D7hgtkzLk%2FnkcQipKwQzePOeEDrYVVa64qu1K02Mshg63bLqV5UHdqcvC2rKjuw6h0e71iVTN2RwqC%2FWAES3KjEVAR5FF1Zuf0M83nhvB7wsgfuBp9F3RPP0sHo1DWd7dVEdXKgUyOXuT1UqJ0PWIzMZOr18RYav6TWOYZ4V%2FN1d%2FC3KL%2B7ueeV1VbYMvpJWxTM78ni%2FxOXSiZ%2BQMlGz6FQ%3D%3D
佳诺仰卧板仰卧起坐健身器材仅78元起包邮
</code>
Copy after login
Copy after login

上面的文本,如何变成2组,每组包括地址和标题?
我用下面的正则匹配出了5组搞了半天没搞出来

javascript - 正则表达式,如何分组?地址和标题分一组

先把最后的"\n"去掉啊,不过既然是分行的,干嘛不s.split("\n")

就这样分组就行,但是要遍历析取,每次取出两组,用javascript实现:

var str = 'http://s.click.taobao.co/t?e=m=2...',
  matchArr,
  REGEX = /(.*)([\u4e00-u9fa5]*)\n?/g;

while ((matchArr = REGEX.exec(str))) {
  var address = matchArr[1], 
    title = matchArr[2];

  console.log(address);
  //http://s.click.taobao.com/t?e=m=2...

  console.log(title);
  //创意男女雨伞长柄伞...
}
Copy after login
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Can the Python interpreter be deleted in Linux system? Can the Python interpreter be deleted in Linux system? Apr 02, 2025 am 07:00 AM

Regarding the problem of removing the Python interpreter that comes with Linux systems, many Linux distributions will preinstall the Python interpreter when installed, and it does not use the package manager...

How to solve the problem of Pylance type detection of custom decorators in Python? How to solve the problem of Pylance type detection of custom decorators in Python? Apr 02, 2025 am 06:42 AM

Pylance type detection problem solution when using custom decorator In Python programming, decorator is a powerful tool that can be used to add rows...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

Python 3.6 loading pickle file error ModuleNotFoundError: What should I do if I load pickle file '__builtin__'? Python 3.6 loading pickle file error ModuleNotFoundError: What should I do if I load pickle file '__builtin__'? Apr 02, 2025 am 06:27 AM

Loading pickle file in Python 3.6 environment error: ModuleNotFoundError:Nomodulenamed...

What should I do if the '__builtin__' module is not found when loading the Pickle file in Python 3.6? What should I do if the '__builtin__' module is not found when loading the Pickle file in Python 3.6? Apr 02, 2025 am 07:12 AM

Error loading Pickle file in Python 3.6 environment: ModuleNotFoundError:Nomodulenamed...

How to ensure that the child process also terminates after killing the parent process via signal in Python? How to ensure that the child process also terminates after killing the parent process via signal in Python? Apr 02, 2025 am 06:39 AM

The problem and solution of the child process continuing to run when using signals to kill the parent process. In Python programming, after killing the parent process through signals, the child process still...

How to use Pandas to implement column-to-column statistics of data? How to use Pandas to implement column-to-column statistics of data? Apr 02, 2025 am 06:15 AM

How to use Pandas to implement column-to-column statistics of data? In data analysis, you often encounter situations where data needs to be reorganized and counted. For example, there is a...

See all articles