Tuesday, 15 January 2013

bash - Regex to search all files that does not contain an id in button tags -


I do not know regex and it is rarely used I'm trying to identify html button tags without id I ended up with this

  $ grep -Prn '& lt; Button (. *) (?! \ Id) (. *) & Gt; . But the search results & lt; Button ... ID ... & gt; Came with. & Lt; Button id = "criar_rascunho" class = "botao-editar botao-claro" onclick = "editarConteudoRoteiro ('' php echo $ roteiro_versao- & gt; getId () ;? & gt; ',' & lt ?? php Echo $ roteiro_release- & gt; getId () ;? & gt; ') "& gt; & Lt; Button class = "botao-claro botao-progresso" data-title = " Translation ('Vir-Progo');? & Gt; & gt; Button & gt; & lt; Button class =" Exclier-Displina Exclair-Displenna-Icons "> 

In other words, both

  & Lt; button ... & gt;  

and

  & lt; button ... ID ... & gt;  

are in search results.

You can try the following .

  grep -Prn '& lt; button \ b (?! ^ ^ \ Bid \ b) [^ & gt;] * & gt;  

(?! [^ & Gt;] * \ bid \ b) Negative lookhead which claims to match & lt; Button won

Example:

  $ cat file  

button ... & Gt; & lt; button ... ID & gt; $ Grep -Prn '& lt; button \ b (?! [^ & Gt;] * \ bid \ b) [^ & gt;] * & gt; ' File 1: Click the button ... & gt;


No comments:

Post a Comment