Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex: How to specify captured group should contain a specfic word

Tags:

regex

php

Question : How to match anchor tag which has ID attribute?

My string

<a href="something" id="someid" />
<a href="something" />

Expected output:

<a href="something" />
<a href="something" />

I need to delete id attribute in anchor tags.

I tried so far :

 <a(.*?)>  //how to specify `id` should be in the captured group

Note: I have not used DOM parser for this, as it saves as HTML.

like image 705
Learning Avatar asked Mar 16 '23 21:03

Learning


1 Answers

Check on this : https://regex101.com/r/cN9nR3/3

Expression : <a[^>]*(id="[a-z]*").*> should do it.

like image 183
Falt4rm Avatar answered Apr 26 '23 12:04

Falt4rm