0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

正規表現メモ

Posted at

よく使う正規表現のメモ

PHP

$h = '<a href="https://google.com" title="google">Google</a>';

if(preg_match('!<a href="([^"]+)"[\\s\\S]*?>([\\s\\S]*?)</a>!', $h, $m)) {
	print_r($m);    // ==> Array ( [0] => Google [1] => https://google.com [2] => Google )
}

Nodejs

let h = '<a href="https://google.com" title="google">Google</a>';
let result = /<a href="([^"]+)"[\s\S]*?>([\s\S]*?)<\/a>/.exec(h);
if(result){
	console.log(result);
	/*
			[
				'<a href="https://google.com" title="google">Google</a>',
				'https://google.com',
				'Google',
				index: 0,
				input: '<a href="https://google.com" title="google">Google</a>',
				groups: undefined
			]
	 */
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?