Search string literals in my code

In my company, we recently noticed that one developer did not use language files, but put the text directly in the code.

My idea was to look for words between quotation marks with at least 1 or more spaces. But I'm a bit like

("|')(\w|\s{1,})*('|") 

this matches the text, but does not require that it has at least 1 word and at least 1 space (so that it matches anything between quotation marks). Can anyone help me out?

The language I want to use for this is PHP (or I could do a search in notepad ++)

+6
source share
1 answer

If you want to combine single or double quotes (without screens) containing a "word" and a space that you could use:

 "(?=[^"\n]*\w)(?=[^"\n]*\s)[^"\n]+"|'(?=[^'\n]*\w)(?=[^'\n]*\s)[^'\n]+' 

In PHP, it will look like this:

 preg_match_all("/\"(?=[^\"\n]*\\w)(?=[^\"\n]*\\s)[^\"\n]+\"|'(?=[^'\n]*\\w)(?=[^'\n]*\\s)[^'\n]+'/", $string, $matches); 
+2
source

Source: https://habr.com/ru/post/907106/


All Articles